[英]Running a python script on C# not working
I have this code that I'm trying to run a Python script. 我有尝试运行Python脚本的这段代码。 It works correctly when I do it manually via the command prompt but if I try to do it via a button click in a C# Windows form it doesn't work.
当我通过命令提示符手动执行此操作时,它可以正常工作,但是如果我尝试通过按钮执行操作,请在C#Windows窗体中单击它不起作用。
private void btnGenerateAndrowarn_Click(object sender, EventArgs e) {
string[] filePaths = Directory.GetFiles(@"C:\Users\User1\Desktop\Android Tools\androwarn\Samples", "*.apk");
foreach (string fileName in filePaths) {
ProcessStartInfo startInfo;
Process process;
string directory = @"C:\Users\User1\Desktop\Android Tools\androwarn\";
string script = "androwarn.py";
startInfo = new ProcessStartInfo("python");
startInfo.WorkingDirectory = directory;
startInfo.Arguments = directory + script + " -i " + fileName + " -r html -v 3";
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
process = new Process();
process.StartInfo = startInfo;
process.Start();
}
}
最有可能的是python
不在您的%PATH%中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.