执行PS脚本时,Windows进程因ExitCode = -1073741819而失败

时间:2019-05-20 10:59:43

标签: windows powershell ssis process

我有一个执行某些逻辑的PowerShell脚本。如果我使用PowerShell ISE运行该脚本,则代码可以正常工作,并且不会生成任何错误。如果我使用创建Windows进程的SSIS运行相同的代码,该Windows进程在相同的凭据下调用相同的脚本,它将失败,并显示退出代码-1073741819,并且该进程没有任何错误(p.StandardError为空-请检查以下代码)。

示例代码:

p = new Process();
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = <path_to_powershell.exe>;
p.StartInfo.Arguments = $"-NoProfile -NonInteractive -ExecutionPolicy Unrestricted -File \"<powershell_script_path>\"";

p.Start();

string stderr = p.StandardError.ReadToEnd();
string stdout = p.StandardOutput.ReadToEnd();

var processExited = p.WaitForExit(10800000);

int succ = (p.ExitCode != 0 || stderr.Length > 0 || !processExited) ? 0 : 1;

// Here it fails because p.ExitCode is not 0 but -1073741819

相同的代码对于其他几个脚本也可以正常工作,但是由于某种原因,对于一个脚本而言,它失败。如前所述,如果我手动运行相同的脚本,则可以正常运行。

0 个答案:

没有答案