【发布时间】:2014-01-31 01:58:23
【问题描述】:
我正在尝试在命令中运行具有不同值的命令(基于用户在运行时在表单文本框中键入的内容。
我看过一些不同的示例,但由于示例之间的歧义或类调用与我的示例不匹配而无法实现它们。
基本上,我试图让代码在命令提示符下运行命令,然后在富文本框中显示输出。到目前为止,我已经尝试过 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();
}
实现我的请求的正确方法是什么?谢谢。
【问题讨论】: