首页 > 解决方案 > 执行 PS 脚本时,Windows 进程失败,ExitCode = -1073741819

问题描述

我有一个执行一些逻辑的 PowerShell 脚本。如果我使用 PowerShell ISE 运行该脚本,代码可以正常工作并且不会产生错误。如果我使用 SSIS 运行相同的代码,该 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

相同的代码适用于其他几个脚本,但由于某种原因,这个脚本失败了。正如我之前解释的,如果我手动运行相同的脚本,它可以正常工作。

标签: windowspowershellssisprocess

解决方案


推荐阅读