我不断收到错误消息System.ComponentModel.Win32Exception: The specified executable is not a valid application for this OS platform.
当我尝试运行这段代码时。
看来这条线myProcess.Start()
是问题所在。
谁能帮我吗。
string python = @"C:\Users\mk\Desktop\A.py";
// python app to call
string myPythonApp = "sum.py";
// dummy parameters to send Python script
int x = 2;
int y = 5;
// Create new process start info
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(python);
// make sure we can read the output from stdout
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
// start python app with 3 arguments
// 1st arguments is pointer to itself,
// 2nd and 3rd are actual arguments we want to send
myProcessStartInfo.Arguments = myPythonApp + " " + x + " " + y;
Process myProcess = new Process();
// assign start information to the process
myProcess.StartInfo = myProcessStartInfo;
Console.WriteLine("Calling Python script with arguments {0} and {1}", x, y);
// start the process
myProcess.Start();
}
}
}
您正在尝试致电A.py
作为可执行文件,例如.exe
,但它不是(它只是文本,而不是程序集)。
相反,你可以通过CMD调用Python来运行A.py
,并传入sum.py
作为额外的参数。
这是一个例子:
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("cmd.exe");
// run python from console.
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.Arguments = "/C python A.py " + myPythonApp + " " + x + " " + y;
Process myProcess = new Process();
myProcess.StartInfo = myProcessStartInfo;
// start the process
myProcess.Start();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)