| Chris Chiasson 2007-02-21, 8:09 am |
| Also, here are the contents of the four line test.bat file I used:
@echo off
echo %1
echo %2
pause
On 2/20/07, Chris Chiasson <chris@chiasson.name> wrote:
> I believe I figured out what happened to the Run command on Windows
> and why it sometimes requires an extra set of quotation marks. The
> reason is given directly in the output of the help command. Just type
>
> C:\>help cmd
>
> in a DOS box. After the description of the command line switches,
> there are two paragraphs and a numbered list. Read the second
> paragraph and the numbered list. Also, read the description for the /S
> command line switch.
>
> It should then be plain what cmd is doing. cmd is stripping the outer
> quotation marks and then processing the command.
>
> For instance, this command works well from a regular command line:
>
> C:\>"C:\Program Files\test.bat" "hi up"
>
> However, if one isn't mindful of the rules above, the following
> command might be expected to work:
>
> C:\>cmd /c "C:\Program Files\test.bat" "hi up"
>
> However, according to the processing rules given in the help output,
> the first and last quotation marks are stripped, leading to the error:
>
> 'C:\Program' is not recognized as an internal or external command,
> operable program or batch file.
>
> To avoid this behavior, the /s switch can be fed to cmd and the
> argument to cmd can always be quoted:
>
> C:\>cmd /s /c ""C:\Program Files\test.bat" "hi up""
>
> Anyway, I believe the failure to add the outer quotation marks and the
> /s switch is a problem with Mathematica, and that the run command
> should be altered appropriately in the next version.
>
> For those that do not want to wait, Robby Villegas' trap method works
> quite well for overloading Run to always add outer quotation marks
> (but you won't be able to add the /s switch, so things may not always
> work out properly):
>
> Unprotect@Run;
> Update@Run;
> $TrapRun=True
> Run[args__]/;$TrapRun:=
> Block[{$TrapRun=False},
> Run["\""<>StringJoin@
> BoxForm`Intercalate[ToString[#,InputForm
]&/@{args}," "]<>"\""]];
> Update@Run;
> Protect@Run;
>
> P.S. Does anyone know why Update is sometimes needed when unprotecting
> variables? I just add the statements out of habit right now.
>
>
> On 5/22/06, Chris Chiasson <chris.chiasson@gmail.com> wrote:
>
>
> --
> http://chris.chiasson.name/
>
--
http://chris.chiasson.name/
|