[Mono-list] ProcessStartInfo and arguments with a backslash
Yves Goergen
nospam.list at unclassified.de
Sat Oct 1 14:17:24 EDT 2011
Hi,
I am debugging a problem with my .NET application calling a UNIX
programme with arguments. The bash command line looks like this:
/usr/bin/smem -P '/usr/sbin/exim4(\s|$)'
My C# code to do exactly that is the following:
string processPath = "/usr/sbin/exim4(\s|$)";
ProcessStartInfo psi = new ProcessStartInfo(
"smem",
"-P '" + processPath + "'");
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
Process p = Process.Start(psi);
But this is what the started programme gets as arguments:
['/usr/bin/smem', '-P', '/usr/sbin/exim4(s|$)']
Notice the "\s" above was changed into "s" which makes the whole thing
fail in the end. The backslash from my argument was entirely removed.
The bash call above would make the smem application see the following
(correct) arguments instead:
['/usr/bin/smem', '-P', '/usr/sbin/exim4(\\s|$)']
I assume the doubled backslash comes from Python's output formatting.
The Python code used to print out all arguments is this:
print repr(sys.argv)
But I'm no Python expert - this code is just copied from somewhere else...
I haven't found a trace of this issue on the Web, so is it by
undocumented intention or is it a Mono bug? What would be the best
workaround? I'm not feeling good with adding just as many more
backslashes until it works. It may fail at any time in the future if I
don't fully understand what's going on here.
Mono version:
Mono JIT compiler version 2.10.5 (Debian 2.10.5-1~dhx1~lucid1)
>From badgerports for Ubuntu 10.4.
--
Yves Goergen "LonelyPixel" <nospam.list at unclassified.de>
Visit my web laboratory at http://beta.unclassified.de
More information about the Mono-list
mailing list