37,719
社区成员
发帖
与我相关
我的任务
分享
class ControlPython
{
public void startexe()
{
Process usepy = new Process();
string path = "\"" + System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
+ "\\pyproject.exe" + "\"";
usepy.StartInfo.FileName = @"python";
usepy.StartInfo.Arguments = path;
usepy.StartInfo.UseShellExecute = false;
usepy.StartInfo.RedirectStandardOutput = true;
usepy.StartInfo.RedirectStandardInput = true;
usepy.StartInfo.RedirectStandardError = true;
usepy.StartInfo.CreateNoWindow = false;
usepy.OutputDataReceived += (sender, args) => Console.WriteLine("received output: {0}", args.Data);
usepy.Start();
sepy.BeginOutputReadLine();
Console.ReadLine();
}
}
usepy.StartInfo.FileName = @"python";
usepy.StartInfo.Arguments = path;
不懂c#, 感觉这两句的意思是, 运行"python \path\to\pyproject.exe"(因为path是参数, python是(要运行的)文件名). 是不是应该改成(只是大概意思, 具体语法你自己来, 我就不懂上面的@是怎么会事):
usepy.StartInfo.FileName = path;
usepy.StartInfo.Arguments = ""; //不知道空字符串是否表示没有参数