2016-03-19 7 views
0

を使用してSTART.EXEは、私は、このコマンドで<code>Process</code>を使用してMSIパッケージをインストールしたプロセス

// 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); 

は、今私は、このコマンドを実行したいが、使用してstart.exe

start /wait msiexec.exe /norestart /qn /l*v! mylog.log /i package.msi 

しかし、今、私は実行し、この:

// 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); 

しかし、それを実行しているとき、私はExceptionを得る:システムファイルがを指定見つけることができません。また、UseShellExecutetrueに設定してみましたが、もう一度Exceptionを取得しました。IOストリームをリダイレクトするには、ProcessオブジェクトのUseShellExecuteプロパティをfalseに設定する必要があります。

したがって、startコマンドをC#を使用して実行できますか?

+0

ファイルパスにすべてのパスを入れて、引数を削除して、ファイルパスが正しいことを確認しましたか? –

+2

'start'はプログラムだとは思っていませんが、' cmd'によって提供されたものです。 –

+0

Nop、別のコマンドプロンプトでコマンドを実行し始める – Andres

答えて

3

このようなものを試してみてください。

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; 

私はCMDを使用して開始コマンドを実行する必要があると思います。

+0

あなたはロックマン!完璧に働いた! – Andres

関連する問題