Reputation: 6200
I was installing an MSI package using Process
with this command:
msiexec.exe /norestart /qn /l*v! mylog.log /i package.msi
With this C# code:
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "msiexec";
p.StartInfo.Arguments = "/norestart /qn /l*v! mylog.log /i package.msi";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WorkingDirectory = workingDir;
p.Start();
string output = p.StandardOutput.ReadToEnd();
bool status = p.WaitForExit(timeout);
Now I want to run this command but using start.exe
:
start /wait msiexec.exe /norestart /qn /l*v! mylog.log /i package.msi
But now when I run this:
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "start";
p.StartInfo.Arguments = "/wait msiexec.exe /norestart /qn /l*v! mylog.log /i package.msi";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WorkingDirectory = workingDir;
p.Start();
string output = p.StandardOutput.ReadToEnd();
bool status = p.WaitForExit(timeout);
But when running it I get an Exception
: The system cannot find the file specified. Also tried setting UseShellExecute
to true
but then I get another Exception
: The Process object must have the UseShellExecute property set to false in order to redirect IO streams.
So, is it possible to run the start
command using C#?
Upvotes: 0
Views: 706
Reputation: 674
Try something like this.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = @"/c start /wait msiexec.exe /norestart /qn /l*v! mylog.log /i package.msi";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WorkingDirectory = workingDir;
I think you need to use CMD to execute the start command.
Upvotes: 3