Search code examples
c#argumentsprocessstartinfo

C# Problem with ProcessStartInfo


I am using a ProcessStartInfo to patch a file with a text file like this (through cmd.exe):

app.exe temp.txt patch.ips

I wrote this code:

ProcessStartInfo P = new ProcessStartInfo("app.exe");  
P.Arguments = "temp.txt " + _patchpath;  
P.CreateNoWindow = true;  
P.UseShellExecute = false;  
P.RedirectStandardOutput = true;  
Process.Start(P);

app.exe and temp.txt are relative to my application path (note: app.exe isn't the name of my C# application, it's just a program I'm using for the Process), but _patchpath is an absolute path like D:\blah\file.ips. The problem is, the process doesn't work (_patchpath is supposed to be patched with the file temp.txt) if its absolute, but does work if its relative to my app directory. Why is that and how can I fix it?

If I need to be clear please let me know.


Solution

  • The problem is most likely that the called application (app.exe) does not understand the parameters. The best way to solve this issue would be to debug app.exe with the parameters that you provide in the case it doesn't work. Try to set the arguments in the debugger for app.exe to exactly the same parameters as the failed case, and inspect the variables that result from parsing the arguments.