c#调用执行python脚本,并传递参数

[ 2023-01-29 08:47:54 | 作者: admin ]
字号: | |
using System;
using System.Collections;
using System.Diagnostics;
  
namespace Test
{
     class Program
     {
         static void Main(string[] args)
         {
             Process p = new Process();
             string path = "reset_ipc.py";//待处理python文件的路径,本例中放在debug文件夹下
             string sArguments = path;
             ArrayList arrayList = new ArrayList();
             arrayList.Add("com4");
             arrayList.Add(57600);
             arrayList.Add("password");
             foreach (var param in arrayList)//添加参数
             {
                sArguments += " " + sigstr;
             }
  
             p.StartInfo.FileName = @"D:\Python2\python.exe"; //python2.7的安装路径
             p.StartInfo.Arguments = sArguments;//python命令的参数
             p.StartInfo.UseShellExecute = false;
             p.StartInfo.RedirectStandardOutput = true;
             p.StartInfo.RedirectStandardInput = true;
             p.StartInfo.RedirectStandardError = true;
             p.StartInfo.CreateNoWindow = true;
             p.Start();//启动进程
  
             Console.WriteLine("执行完毕!");
  
             Console.ReadKey();
         }
     }
}
  


文章:
c#调用python的四种方法 https://blog.csdn.net/qq_42063091/article/details/82418630
评论Feed 评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=2916

这篇日志没有评论。

此日志不可发表评论。