1

我有这段代码,我正在尝试运行 Python 脚本。当我通过命令提示符手动执行此操作时,它可以正常工作,但如果我尝试通过在 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();
  }
}
4

1 回答 1

0

这很可能python不在您的 %PATH% 中。

于 2012-10-14T14:02:16.053 回答