Despite of this question covers Windows CMD, AutoHotkey and MultiMarkdown, I believe, the problem is closely related to CMD (my lack of knowledge of Windows bat files).
So...
I'm trying to create AHK-script for MultiMarkdown, which will allow to convert mmd files to any extension (not particulary html).
This is how I could do it with plain bat file:
chcp 65001
set ext=mmd2html
for %%i in (*.md) do call multimarkdown --escaped-line-breaks --process-html --nosmart "%%i" > %%~ni.%ext%
This works. If you place this bat file together with your mmd-files, it will properly convert and rename them.
However, when I'm trying to place this code into AHK script, it fails. Here is what I have:
#SingleInstance, Force
f1::
bat_script =
(join&
chcp 65001
set ext=mmd2html
for `%i in (*.md) do call multimarkdown --escaped-line-breaks --process-html --nosmart "`%i" > `%~ni.`%ext`%
)
Run, %ComSpec% /c %bat_script%, %A_ScriptDir%
return
How it can be solved?
Post updated
The actual problem is that instead of renaming files like this:
my_test_file.md --> my_test_file.mmd2html (yes, "mmd2html" is an extension)
it renames literally:
my_test_file.md --> my_test_file.%ext%
In other words, the script doesn't understand that %ext%
is variable. Here is working AHK code, without using var:
f1::
bat_script =
(join&
chcp 65001
for `%i in (*.md) do call multimarkdown --escaped-line-breaks --process-html --nosmart "`%i" > `%~ni.aaaaaaaa
)
Run, %ComSpec% /c %bat_script%, %A_ScriptDir%
return
However, I want to use variable for file extension, so this working code posted here just for demonstration purposes.
%
chars is different for your AHK wrt your batch. - Magoo%%
if bat-script launched from bat-file, and we should use single%
if the same code pasted directly into cmd window. This was the reason why I reduced them. However, I've also triedfor
%%i in (*.md) do call multimarkdown --escaped-line-breaks --process-html --nosmart "
%%i" >
%%~ni.
%ext%
. It will immediately close the cmd window, without any effect. - john c. j.for %i in ("c:\full path\*.md") do ...
orcd /d "c:\full path" & for %I in (*.md) do...
(I'll leave proper escaping to you, 'cause I don't speak AHK) - Stephan%A_ScriptDir%
specifies the "current directory" that the command runs from, make sure that points to where the.md
files are (I also do not know AHK). - TripeHoundmy_test_file.md
tomy_test_file.mmd2html
, it renames itmy_test_file.%ext%
. Literally. For some reason, it doesn't understand that%ext%
is variable. I've updated post. - john c. j.