Page 1 of 1
How do I identify a console process?
Posted: Wed Sep 19, 2018 10:14 am
by HansSchl
I am using Ranorex 4.0 under Windows 8.1 64-bit. My test case requires to run a helper application that has no GUI, and to wait for this application to finish before the test case continues. I can launch the application by a "Run application" step, but how can I use "Wait for" to wait until the console application has finished?
Re: How do I identify a console process?
Posted: Wed Sep 19, 2018 12:56 pm
by odklizec
Hi,
Ranorex 4.0 is pretty old and I doubt there is anyone who can even remember its coding possibilities? Generally speaking, you should be able to write a "search process" method, in which you can wait for the process termination.
Here are few process -related examples, whcih should help you with writing such method:
https://stackoverflow.com/questions/262 ... is-running
https://social.msdn.microsoft.com/Forum ... nning-in-c
https://support.microsoft.com/en-us/hel ... g-visual-c
Re: How do I identify a console process?
Posted: Wed Sep 19, 2018 12:59 pm
by HansSchl
Sorry... I read the wrong line in the "About" dialog. Ranorex version is 8.2.1
Downloaded and installed today...
Re: How do I identify a console process?
Posted: Wed Sep 19, 2018 1:02 pm
by odklizec
Good
In any case, you will have to write your own method to wait for the end of process. The links I posted should help you with this task.
Re: How do I identify a console process?
Posted: Wed Sep 19, 2018 1:04 pm
by HansSchl
I had hoped it's built into Ranorex. Thanks anyway...
Re: How do I identify a console process?
Posted: Wed Sep 19, 2018 1:06 pm
by odklizec
Nope, there is no such "wait" available. Existing wait actions are UI related
Re: How do I identify a console process?
Posted: Wed Sep 19, 2018 1:12 pm
by asdf
Hi,
The easiest way would be to start the application through code and wait for the exit code of it.
Code: Select all
using System.Diagnostics;
...
Process process = new Process(); // Configure the process using the StartInfo properties.
process.StartInfo.FileName = "process.exe";
process.StartInfo.Arguments = "-YourArguments";
process.Start();
process.WaitForExit();// Waits here for the process to exit.
Hope that helps.
ASDF
Re: How do I identify a console process?
Posted: Wed Sep 19, 2018 2:45 pm
by HansSchl
Ok, that would be a complete action that launches the console app and only returns when the app has terminated. What if I wanted to do something else while the app is running, and at some later step of my test case wait for the app to terminate? Can I write a function with a signature like 'bool ProcessExists(string procName)', and use it in a 'Wait for' action?
Re: How do I identify a console process?
Posted: Thu Sep 20, 2018 7:39 am
by HansSchl
I solved the problem. Thank you for pointing me into the correct direction
Code: Select all
[UserCodeMethod]
public static void RunProgramAndWait(string path, string args, int waitSeconds)
{
Process process = new Process(); // Configure the process using the StartInfo properties.
process.StartInfo.FileName = path;
process.StartInfo.Arguments = args;
if (!process.Start())
throw new RanorexException("Could not create process '" + path + "'");
if (!process.WaitForExit(waitSeconds * 1000))
throw new RanorexException("Process '" + path + "' failed to terminate within " + waitSeconds.ToString() + " seconds");
}