I have a C # command line application that I need to run on windows and under mono on unix. At some point, I want to start a subprocess, given the set of arbitrary parameters that passed through the command line. For example:
Usage: mycommandline [-args] -- [arbitrary program]
Unfortunately, System.Diagnostics.ProcessStartInfo accepts only a string for arguments. This is a problem for commands such as:
./my_commandline myarg1 myarg2 -- grep "abc" foo.txt
In this case, argv looks like this:
argv = {"my_commandline", "myarg1", "myarg2", "--", "grep", "abc", "foo.txt"}
Note that the quotation marks around "abc" are separated by the shell, so if I just concatenate the arguments to create an arg string for ProcessStartInfo, I get:
args = "my_commandline myarg1 myarg2 -- grep abc foo.txt"
This is not what I want.
Is there an easy way to either pass argv to run the subprocess in C # OR, or convert an arbitrary argv to a string that is legal for windows and the Linux shell?
Any help would be greatly appreciated.
c # shell subprocess mono argv
lucas
source share