2
$\begingroup$

Pandoc can convert documents in markdown etc. to HTML etc..

It can be worked well in cmd or bat file.

I want to use Pandoc in Mathematica 10 on Windows7, but it doesn't work.

Method 1:

Export["E:/test.md", "# abcd", "Text"];
Export["E:/test.bat",  "pandoc test.md -f markdown -t html -s -o test.html", "Text"];
Run["E:/test.bat"];(*Nothing is done*)

Patch: It workes well, if I run "test.bat" on Windows.

Method 2:

process = StartProcess[$SystemShell];
WriteLine[process, "E:"];
WriteLine[process, "md abcd"];
WriteLine[process, "cd abcd"];
WriteLine[process, "echo # abcd >> test.md"];
WriteLine[process, "pandoc test.md -f markdown -t html -s -o test.html"];(*Nothing is done*)
WriteLine[process, "exit"];
KillProcess /@ Processes[];

Patch: The path of Pandoc is in Environment["PATH"].

The Right Way for Method 2:

SetDirectory["E:/"];
process = StartProcess[$SystemShell];
WriteLine[process, "E:"];
WriteLine[process, "md abcd"];
WriteLine[process, "cd abcd"];
WriteLine[process, "echo # abcd >> test.md"];
WriteLine[process, "pandoc test.md -f markdown -t html -s -o test.html"];(*This is Worked*)
WriteLine[process, "exit"];
KillProcess /@ Processes[];

Method 1 (Corrected):

SetDirectory["E:/"];
Export["E:/test.md", "# abcd", "Text"];
Export["E:/test.bat",  "pandoc test.md -f markdown -t html -s -o test.html", "Text"];
Run["E:/test.bat"];
$\endgroup$
3
  • 1
    $\begingroup$ Why aren't you launching the pandoc executable directly? Can you explain why you think that it is necessary to write the command to a batch file first and try to run that? $\endgroup$
    – Szabolcs
    Commented Jan 5, 2016 at 8:54
  • 1
    $\begingroup$ Also, can you explain why you phrased the question to be specific to pandoc? Did you try running any other programs? Did you try running pandoc in a standard Windows command window? If it is specific to pandoc, are you sure it's not because of how pandoc is installed on your computer (installation location, is it added to the PATH, is the modified PATH picked up by Mathematica, etc.) $\endgroup$
    – Szabolcs
    Commented Jan 5, 2016 at 9:05
  • $\begingroup$ The pandoc command works well in a standard Windows command window. And the "test.bat" also works in windows. My trouble is why the pandoc commad is useless but others commads are executed. $\endgroup$
    – Li Xuan
    Commented Jan 5, 2016 at 9:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.