Reputation: 547
I have to trigger another application after user done with my GUI. In order to trigger another application, i have to pass some command line argument to start that application. Let's say I have to pass below arguments:
c:\Program File\application.exe -name text -cmdfile c:\text\open.txt
The application.exe is a parameter that i want to pass to another applcation.
Before, that application set those argument in Visual Studio -> Properties -> Debug as "c:\Program File\application.exe" -name text -cmdfile c:\text\open.txt
As i understand, every space in above string consider as an argument except the one inside double quotes, so "c:\Program File\application.exe" is the first argument, -name is the second and text is the third. However, if i am using ProcessStartInfo.Argument property, if I set "c:\Program File\application.exe" -name text -cmdfile c:\text\open.txt, it first of all give an error, and than I add double quotes at the end of string, another application consider c:\Program as first argument and File\application.exe as second argument.
How can I avoid space as the separator for arguments? How can I pass the whole string as the same format setup in Visual Studio -> Properties -> Debug as "c:\Program File\application.exe" -name text -cmdfile c:\text\open.txt using ProcessStartInfo.Argument property?
ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.Arguments = "c:\Program File\application.exe" -name text -cmdfile c:\text\open.txt
(error)
if
startInfo.Arguments = "c:\Program File\application.exe -name text -cmdfile c:\text\open.txt"
it takes c:\Program as first argument and File\application.exe as second argument.
How can I figure this out? Any experience on that? Thank you in advance.
Upvotes: 1
Views: 6259
Reputation: 7737
Your question is a little unclear. Do you want to start application.exe
, or are you passing that as a parameter?
If you are starting it you can use:
var startInfo = new ProcessStartInfo(@"c:\Program File\application.exe");
startInfo.Arguments = @"-name text -cmdfile c:\text\open.txt";
Process.Start(startInfo);
If you are trying to start another process and want to pass application.exe
as a parameter with the other parameters you could try:
var startInfo = new ProcessStartInfo("application2.exe");
startInfo.Arguments = @"""c:\Program File\application.exe"" -name text -cmdfile c:\text\open.txt";
Process.Start(startInfo);
Upvotes: 2