I'm trying to use the Win7 command prompt from a Mathematica notebook.
I'd like to do a couple simple things, but I can't seem to get the syntax straight:
- open explorer.exe in a specific location
- open a command prompt and run several commands
The Wolfram tutorial on external programs says:
Note that when you use Run, you must not preface commands with exclamation points. Run simply takes the textual forms of the arguments you specify, then joins them together with spaces in between, and executes the resulting string as an external shell command.
This seems to work as it should:
Run["C:\\Windows\\explorer.exe"]
But this snippet seems to ignore the additional parameters when I call it from Mathematica:
Module[{cmd="C:\\Windows\\explorer.exe /e, & \"" <> $UserAddOnsDirectory <> "\""},
Print@cmd;
Run[cmd]]
even though the syntax as displayed by the Print
statement is correct syntax and works as expected from the OS command line.
RunProcess
(and relatedStartProcess
,KillProcess
), much easier to set up complicated command chains. It constructs the actual command to conform to the actual platform it is run on, concerning paths, spaces, escape characters, etc. $\endgroup$Run["C:/windows/explorer /e"]
,Run["C:\\windows\\explorer /e"]
,Run["C:/windows/explorer", "/e"]
,Run["C:\\windows\\explorer", "/e"]
) work the same way as direct executing from the command line (within thecmd
process) of the commandexplorer /e
: it opens the "My Documents" folder. $\endgroup$