Run batch file when argument contains quotes and spaces (from .NET framework)

Posted by turtle on Stack Overflow See other posts from Stack Overflow or by turtle
Published on 2009-05-06T15:22:12Z Indexed on 2010/04/13 17:03 UTC
Read the original article Hit count: 235

Filed under:
|

I have a bat file which sets some environment variables, and then executes a command on the command line. I want to replace the hard coded command with one passed in via a parameter.

So:

:: Set up the required environment
SET some_var=a
SET another_var=b
CALL some.bat

:: Now call the command passed into this batch file
%1

The problem is that the command is complex, and doesn't escape cleanly. It looks like this:

an.exe -p="path with spaces" -t="some text" -f="another path with spaces"

I'm trying to call the .bat from a .NET framework app, using:

Dim cmd as String = "the cmd"
System.Diagnostics.Process.Start( thebat.exe, cmd )

but I can't seem to get the escapes to work correctly. Can someone tell me how the string cmd should be entetered to get the command passed into the bat file as an argument correctly?

© Stack Overflow or respective owner

Related posts about .bat

Related posts about batch