0
我想在命令運行具有不同值的命令捕捉CMD輸出(基於什麼類型的用戶到表單文本框在運行時。無法從RedirectStandardOutput
我見過幾個不同的例子並且由於示例中含糊不清或者因爲類調用與我的示例不匹配而無法實現它們。
基本上,我試圖讓代碼在命令提示符下運行命令,然後顯示在一個富文本框中的輸出。我試圖嘗試StreamReader
到目前爲止,無濟於事。我得到錯誤StandardOut has not been redirected or the process hasn't started yet.
當運行此。
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
string contentType = "\"Content-Type:text/xml\"";
string output = string.Empty;
string command = @"c:\curl -s -k -H "+contentType+" -u "+txtBoxIntgrName.Text+":"+txtBoxIntgrPass.Text+" -g https://"+txtBoxDomain.Text+"/wabapps/bb-data-integrat-flatfile-BBLEARN/endpoint/dataSetStatus/"+txtBoxReferenceID.Text;
startInfo.Arguments = "/user:Administrator \"cmd /c " + command + "\"";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo = startInfo;
process.Start();
using (StreamReader streamReader = process.StandardOutput)
{
rchTxtBoxDataSetStatus.Text = streamReader.ReadToEnd();
}
什麼是實現我的請求的正確方法?謝謝。
http://stackoverflow.com/questions/15032643/get-values-from-process-standardoutput – urbanlemur