windows - 执行 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
相同的代码适用于其他几个脚本,但由于某种原因,这个脚本失败了。正如我之前解释的,如果我手动运行相同的脚本,它可以正常工作。
解决方案
推荐阅读
- java - 使用 GSON 的 fromJson() 时出现 IllegalArgumentException
- java - Spring Boot找不到主类多模块
- c++ - 如何完全清除 QTreeWidget 选择?
- ios - 如何在 Swift 4 中删除 CoreData 的对象
- ajax - 带有 laravel 5.6 的 ajax 帖子
- excel - 在不同单元格中以任何顺序搜索 3 个单词“文本”的公式
- ruby-on-rails - rails first_or_create 不更新现有记录
- python - Python TensorFlow Lite 解释器崩溃
- javascript - 我对Foundation的源代码有些疑惑
- c# - 如何使用 CrmServiceClient 设置空属性值