c#中调用python程序
阿神
阿神 2017-04-17 11:05:33
[Python讨论组]

我在一个winform的c#程序里通过process调用python程序,这个python程序里有多线程。现在问题是我调用的python程序可以跑,但是跑一会就不能运行了,但是我如果单独运行python就没有问题,这是为什么。。` publ

ic void RunPythonScript(string path, string args = "")
        {
            path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "script\\" + path;
            
            p.StartInfo.FileName = "python.exe";
            string sArguments = "\"" + path + "\"";
            if (args.Length > 0)
            {
                sArguments += " " + args;
            }
            //p.StartInfo.WorkingDirectory = "D:\\";
            p.StartInfo.Arguments = sArguments;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            p.Start();
            //p.CloseMainWindow();
            //p.WaitForExit();
        }`
        
        
阿神
阿神

闭关修行中......

全部回复(2)
大家讲道理

有没有考虑使用IronPython呢?
http://ironpython.codeplex.com/

ringa_lee

把下面的这行代码取消注释就可以了。前提你这个操作是在主线程之外。不然会阻塞。

//p.WaitForExit();
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号