2017-08-04 92 views
0

我開始使用我的c#代碼進行一個簡單的過程。我可以打開cmd,但不能在指定的路徑中執行,甚至不執行該命令,而是顯示句柄是無效的錯誤。它使用簡單的winform應用程序完成。使用c#代碼的命令行

下面是我的代碼:

 var process = new System.Diagnostics.Process(); 
     var startInfo = new System.Diagnostics.ProcessStartInfo 
     { 
      WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal, 
      WorkingDirectory = @"D:\Work\Application", 
      FileName = "cmd.exe", 
      RedirectStandardInput = true, 
      UseShellExecute = false 
     }; 

     process.StartInfo = startInfo; 
     process.Start(); 
     process.StandardInput.WriteLine("timeout /t 10"); 

這一天工作之前,但隨後沒有工作。我看不出有什麼問題

+2

的[運行命令行編程代碼(可能的複製https://stackoverflow.com/questions/13738168/run-command -line-代碼編程) –

回答

0

所有你需要做的是:

string cmdText; 
cmdText = "/C timeout /t 10"; 
System.Diagnostics.Process.Start("CMD.exe", cmdText);