I have a to execute a process that sometimes produces an error. However every time it produces that error, it doesn't exit the process.
aneesh@nb-14:~$ emulator -no-boot-anim -avd Andreud
Emulator ERROR: Unable to load VM from snapshot. The snapshot file was saved for a
different hardware configuration
^Z
aneesh@nb-14:~$ emulator -no-boot-anim -avd Andreud
On success the cursor is at the beginning of the second line above and the emulator error doesn't show up. On failure it shows the error but I am forced to stop it. The commands might seem to show that this question is off-topic.
However my question is how (via a command) to detect this error while this process is still running and if yes kill it.
Launch the emulator in the background, sending all of its output to a temporary file
Then get the PID of the recently launched process, and store it in a variable called EMULATORPID
Then, while the emulator is still running, watch the output file for the error, and when it is found, kill the process by PID:
To satisfy the additional requirement of quitting the while loop after five seconds, you could set a counter, increment it each loop, and add a delay of one section to each iteration like so: