How do I run a Python script from C#?
2021-05-31 13:05
标签:private reader str RoCE ade inf rom The standard The reason it isn‘t working is because you have If you don‘t use the shell, you will have to supply the complete path to the python executable as Also note, that you can‘t I‘m not quite sure how the argument string should be formatted for python, but you will need something like this: How do I run a Python script from C#? 标签:private reader str RoCE ade inf rom The standard 原文地址:https://www.cnblogs.com/chucklu/p/14743293.htmlHow do I run a Python script from C#?
UseShellExecute = false
.FileName
, and build the Arguments
string to supply both your script and the file you want to read.RedirectStandardOutput
unless UseShellExecute = false
.private void run_cmd(string cmd, string args)
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = "my/full/path/to/python.exe";
start.Arguments = string.Format("{0} {1}", cmd, args);
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using(Process process = Process.Start(start))
{
using(StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
Console.Write(result);
}
}
}
上一篇:Java多线程
下一篇:src和href属性的区别
文章标题:How do I run a Python script from C#?
文章链接:http://soscw.com/essay/89758.html