Reputation: 18743
I would like to start a process by providing it arguments (not really sure these can be called "arguments"... see below). Now this is a little special:
"C:\\Path To Game\\game.exe" + connect [serverip]
(Note the +
). When I launch this shortcut, the GUI starts and executes the arguments connect [serverip]
(the game actually starts and connects to the server).I tried the following:
Process.Start("C:\\Path To Game\\game.exe + connect [serverip]");
but this obviously end with an Win32Exception "The system cannot find the file specified".
var psi = new ProcessStartInfo();
psi.FileName = "C:\\Path To Game\\game.exe";
psi.Arguments = "+ connect [serverip]";
Process.Start(psi);
and this produce an error in the GUI (the game doesn't start and says "WIN_IMPROPER_QUIT_BODY").
Any ideas how to provide these arguments to my process?
Upvotes: 0
Views: 2314
Reputation: 32571
You have to use:
psi.Arguments = "+connect [serverip]";
(no space between +
and connect
).
Upvotes: 0
Reputation: 43616
Is it possible you need to set the WorkingDirectory
for the game
string exePath = "C:\\Path To Game\\game.exe";
var psi = new ProcessStartInfo();
psi.FileName = exePath;
psi.Arguments = "+ connect [serverip]";
psi.WorkingDirectory = Path.GetDirectoryName(exePath);
Process.Start(psi);
Upvotes: 2
Reputation: 4628
Option 2 is the way to go there but what happened to your '+'? It's not a special character, that was just getting passed through to the command, so you need to include it at the start of psi.Arguments too.
Upvotes: 0