2010-03-25

Mathematica Run and spaces

On Windows I have been trying to interface to another program.  This is due to the PlayerPro not supporting the .NET interface so you can’t do COM object manipulation.  So I am putting any of that code into an exe built by  Autoit and then want Mathematica to call it with variable parameters.

However  I have had real trouble using the Run[] command to run a progam which has a command and a parameter with a filename with spaces in it.

Run[“\”F:\\A dir\\test.exe\" “\”F:\\A dir\\data\"”]

so my work around is to put the command in a batch file Run.bat and then run:

Run[“\”F:\\A dir\\run.bat\"”]

Which is irritating but works.

I used the following to build the command file:

batchRun[workingDir_, command_] := Module[{fn, str},
  fn = workingDir <> "Run.bat";
  If[FileExistsQ[fn], DeleteFile[fn]];
  str = OpenWrite[fn];
  WriteString[str, command];
  Close[str];
  Run["\"" <> fn <> "\""]
  ]

No comments: