1

I'm trying to use cmd CLI to excute a newman collection run. However when the process is running it's getting stuck and never finishes processing.

Any suggestions on how to deal with that?

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");
}

This is the most I can get out of it:

cmd result

It gets stuck here^ and never continues.

Compo
  • 36,585
  • 5
  • 27
  • 39
Aviad
  • 33
  • 8
  • you want to timeout the wait – Soleil Nov 15 '21 at 16:18
  • @Soleil already doing that with the following command: processExited = CliProcess.WaitForExit(TotalTimeout); Am I missing something? – Aviad Nov 15 '21 at 16:26
  • you're waiting on the main thread, it's going to block until it's done – d.moncada Nov 15 '21 at 16:48
  • 1
    @AviadNaamat So update the question with the value of `TotalTimeout`, and you should expect the wait not to last more that this timeout. – Soleil Nov 15 '21 at 18:53
  • @AviadNaamat, I have removed some unnecessary whitespace from your submitted file content, and it clearly highlights that you have not submitted sufficient content for us to reproduce your code for testing purposes. Could you please review it, and at least ensure that the braces are matched; Thank you. – Compo Nov 15 '21 at 19:24
  • @d.moncada it ain't ever done...that's my problem :( – Aviad Nov 16 '21 at 06:11
  • @Soleil , I've updated main code with TotalTimeout value – Aviad Nov 16 '21 at 06:13
  • @Compo, I've removed the brace, I think I've shown all necessary parts of the code – Aviad Nov 16 '21 at 06:13
  • @Aviad, I'm certainly no expert with C#, but I can almost guarantee that simply removing that brace does not correct your code. I am certain, especially because of the escaped closing brace just above the one you've removed, that there was at least one missing brace above what you've submitted, _(and because of the whitespace I removed, it is also highly likely that the code you've submitted is also nested within several more braces too)_. That means your code is not a [mcve] of what you're having a specific issue with, and as a result we cannot properly replicate it, in order to assist you. – Compo Nov 16 '21 at 11:47
  • @Compo I've removed the brace so it will be a minimal reproduce. If I'll put the whole code it'll only bring up more complexity that is unrelated to the issue(some if's about statuses). so this is now should be a full way to reproduce the code minus the actual collection file which I think is the only missing thing within the code context – Aviad Nov 16 '21 at 12:37
  • 1
    So are you saying, @Aviad, that we categorically can rule out any problems with the nesting or code you haven't submitted? and if we were all to run exactly the code as current submitted, it will definitlely run as needed? and reproduce the specific issue you are reporting? I ask because you've now included a line which appears to show that your command being run uses `demo.postman_collection.json`, which none of us have seen the content of. Is that something which is a built-in part of `newman`? Also does the issue occur if that command, and/or the JSON is changed to something else? – Compo Nov 16 '21 at 12:46

1 Answers1

0

the problem was due to the fact that the proxy was misconfigured so the request was sent trying to get to an unresponsive proxy server... So in conclusion, there was nothing wrong with the code itself.

Aviad
  • 33
  • 8