怎么解决用scrapy工程打包的exe文件运行时在cmd输出的信息无法重定向到winform中
如何解决用scrapy工程打包的exe文件运行时在cmd输出的信息无法重定向到winform中?
打包后的exe可以单独运行,也可以被直接在winform项目中启动,但其中的输出信息无法获取到。用普通的C++exe小程序来验证过,同样的状况。所写的代码只能运行系统自带的功能如ipconfig、mspaint之类的。代码如下:
我的目的就是要获取到exe的输出信息并实时输出(不是在cmd中输出),如果有其他的解决方案也请不吝赐教!
T_T 这是我毕设的一部分,Python部分写好了,.NET部分也写好了,就差这关键的一步了,坑啊!
------解决思路----------------------
你反射exe,找到richTextBox,赋值。
打包后的exe可以单独运行,也可以被直接在winform项目中启动,但其中的输出信息无法获取到。用普通的C++exe小程序来验证过,同样的状况。所写的代码只能运行系统自带的功能如ipconfig、mspaint之类的。代码如下:
private void Crawler(List<string> cmdList)
{
process = new Process();
Control.CheckForIllegalCrossThreadCalls = false;
process.StartInfo.FileName = ConfigurationManager.AppSettings["cmdPath"].ToString();
process.StartInfo.WorkingDirectory = ".";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.OutputDataReceived += new DataReceivedEventHandler(CmdShow);
process.Start();
foreach (string cmd in cmdList)
{
process.StandardInput.WriteLine(cmd);
}
process.BeginOutputReadLine();
}
private void CmdShow(object sendingProcess, DataReceivedEventArgs outLine)
{
if (!String.IsNullOrEmpty(outLine.Data))
{
StringBuilder str = new StringBuilder(this.tbCmdLine.Text);
tbCmdLine.Text = str.AppendLine(outLine.Data).ToString();
this.tbCmdLine.SelectionStart = this.tbCmdLine.Text.Length;
this.tbCmdLine.ScrollToCaret();
}
}
我的目的就是要获取到exe的输出信息并实时输出(不是在cmd中输出),如果有其他的解决方案也请不吝赐教!
T_T 这是我毕设的一部分,Python部分写好了,.NET部分也写好了,就差这关键的一步了,坑啊!
------解决思路----------------------
你反射exe,找到richTextBox,赋值。