您当前的位置: 首页 >  Python

txwtech

暂无认证

  • 2浏览

    0关注

    813博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C#调用python脚本文件方法

txwtech 发布时间:2022-09-30 16:37:37 ,浏览量:2

类文件:
namespace WaferSawRouteInspection
{
    public class ClassVisionPythonScript
    {
        private Process p;

        public ClassVisionPythonScript(string path_python_exe, string path_pyfile)
        {
            p = new Process();
            p.StartInfo.FileName = path_python_exe;
            p.StartInfo.Arguments = path_pyfile;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardInput = true;
        }

        //  public string run(img)
        public string run()
        {
            p.Start();
            //     img.GetArray(out var data);
            //  string value = string.Join(',', Array.ConvertAll(data, (byte d) => d.ToString()));
            // p.StandardInput.WriteLine(value);
            p.StandardInput.WriteLine("执行成功");
            string result = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            p.Close();
            return result;
        }
    }
}
调用方法:

 string python_exe = @"C:\Users\xxxxx\AppData\Local\Programs\Python\Python38\python.exe";

 var runpython = new ClassVisionPythonScript(python_exe, python_para);
            AddToMainWindowLog("启动检测任务,传递参数:"+ python_para);
            string msg = runpython.run();

msg获取脚本返回的结果

关注
打赏
1665060526
查看更多评论
立即登录/注册

微信扫码登录

0.0372s