用scrapy工程打包的exe如何获取其 输出信息

.Net技术 码拜 10年前 (2014-12-10) 1775次浏览 0个评论

打包后的exe可以单独运行,也可以被直接在winform项目中启动,但其中的输出信息无法获取到。如何从exe 获取 输出信息?用普通的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部分也写好了,就差这关键的一步了,坑啊!


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明用scrapy工程打包的exe如何获取其 输出信息
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!