1
votes

I'm trying to figure out how to catch any error that occurs from calling this Sikuli script. It launches a Sikuli script which performs numerous tasks and generally runs for about two hours. If any error occurs from it during that time, I need to be able to detect it and then re-run the script. I know how to re-run the script, but I'm not sure how to detect if an error occurred while it was running.

Process Sikulix_Login_Process = new Process();
ProcessStartInfo Sikulix_Login_StartInfo = new ProcessStartInfo();
Sikulix_Login_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
Sikulix_Login_StartInfo.FileName = "cmd.exe";
Sikulix_Login_StartInfo.Arguments = "/c java -jar \"PathToSikuliJarFile\" -r \"PathToSikuliScript\"";

Sikulix_Login_Process.StartInfo = Sikulix_Login_StartInfo;
Sikulix_Login_Process.Start();
2

2 Answers

0
votes

The Process class has two events to monitor output from the process, in this case cmd.exe. The two events are ErrorDataReceived and OutputDataReceived. If the script is writing to text to stdout or stderr it will be sent to the subscriptions of these events. Another option is using the method WaitForExit() and the property ExitCode to wait for the process to finish and then check it's ExitCode. Hope that helps!

0
votes

The right way to do it would be handling the errors from within the script using standard language tools like try ... catch rather than trying to control the jar execution. In case of specific issues with the code itself, please post examples so we can relate to a specific case.