# How to call external commands with parameters on Win7?

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. • I recommend using RunProcess (and related StartProcess, 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. – István Zachar May 2 '15 at 13:49 • On my system (Win7 x64) all possible forms (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 the cmd process) of the command explorer /e: it opens the "My Documents" folder. – Alexey Popkov May 2 '15 at 19:26 ## 1 Answer The following seems to work on Win7 for opening explorer.exe in a specified directory using a command line parameter: Module[{cmd = "C:\\Windows\\explorer.exe /e, \"" <>$UserAddOnsDirectory <>"\""},
Print@cmd;
Run[cmd]]


Also, Rui Liu (Wolfram Technical Support) provides this detailed answer regarding the vagaries of the Run command for Windows systems.

• Actually you don't need to use Run for opening a specific folder, it is sufficient to use SystemOpen, for example SystemOpen[\$UserAddOnsDirectory]. – Alexey Popkov Jun 10 '15 at 14:19
• @AlexeyPopkov that's good to know. Looks like SystemOpen works for a lot of things as long as the corresponding OS Mime type is set up properly. – dionys Jun 10 '15 at 14:35
• Good point about the fragility of SystemOpen (its dependence on the ability of the OS to handle the corresponding MIME type correctly)! I don't know although what corresponds to the directory path? The file:// protocol as in SystemOpen["file://c:"]? – Alexey Popkov Jun 10 '15 at 14:47