I have a java application consisting of a Thread that monitors a table in the database that contains shell scripts to be executed. I look up the database, every few seconds. for a script, execute it (via the Process class), and wait for another script in the table.
My problem is: At times, some command in the script fails. The thread captures the error stream and logs it in the database. However, it keeps logging the messages and the control doesn't return from the script to the Java Thread due to which the subsequent shell scripts in the database are unable to execute.
Is there a work around for this?
Are you reading both standard out and standard error ? Are you doing this in separate threads ? It's possible to block on one or the other depending on how you're consuming the script outputs, and I have a hunch that your script is blocked waiting for the parent process to consume its output.
From the Process documentation:
See this question and the sample code referencing 'stream gobblers'. 2 'gobbler's are created, consuming standard out and standard error.