【发布时间】:2021-12-26 20:14:48
【问题描述】:
我正在尝试使用 cmd CLI 来执行 newman 收集运行。但是,当进程运行时,它会卡住并且永远不会完成处理。
对如何处理有什么建议吗?
string cmdCommand="newman run demo.postman_collection.json --env-var HTTP_PROXY --insecure";
int TotalTimeout= 150000;
CliProcess = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new
System.Diagnostics.ProcessStartInfo();
if (_inputDir != null)
{
startInfo.WorkingDirectory = _inputDir;
}
//startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = false;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C "+cmdCommand;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardInput = true;
bool processExited;
startInfo.RedirectStandardOutput = false;
CliProcess.StartInfo = startInfo;
CliProcess.Start();
CliProcess.StandardInput.WriteLine("exit");
//CliProcess.BeginOutputReadLine();
//CliProcess.BeginErrorReadLine();
//CliProcess.Close();
processExited = CliProcess.WaitForExit(TotalTimeout);
// //&& outputWaitHandle.WaitOne(TotalTimeout) && errorWaitHandle.WaitOne(TotalTimeout);
//CliProcess.CancelOutputRead();
//CliProcess.CancelErrorRead();
//ExitCode = GetProcessExitCode();
//CliProcess.Kill();
//}
//Wait additional minute for the process to exit
if (!processExited)
{
KillNewman();
TraceLogger.Instance.LogMessage(TraceLevel.Warning, MsgSrc, "[SendCmdCommand(string cmdCommand)] Newman process was killed due to timeout");
}
这是我最大的收获:
它卡在这里^并且永远不会继续。
【问题讨论】:
-
你想超时等待
-
@Soleil 已经使用以下命令执行此操作: processExited = CliProcess.WaitForExit(TotalTimeout);我错过了什么吗?
-
你在主线程上等待,它会阻塞直到它完成
-
@AviadNaamat 所以用
TotalTimeout的值更新问题,你应该期望等待不会超过这个超时时间。 -
那么,@Aviad,您是说我们可以断然排除您未提交的嵌套或代码的任何问题吗?如果我们都完全按照当前提交的代码运行,它肯定会根据需要运行吗?并重现您报告的具体问题?我问是因为您现在已经包含了一行似乎表明您正在运行的命令使用
demo.postman_collection.json,我们都没有看到它的内容。那是newman的内置部分吗?如果该命令和/或 JSON 更改为其他内容,也会出现问题吗?
标签: c# cmd command-line-interface newman postman-newman