J
John English
I have a couple of problems using exec():
1) I'm running a program which produces output to both standard
output and standard error streams. How can I read from one or
the other, depending on which has been written to? At the moment
I read from the standard output stream, but this blocks if there
is nothing to be read and I never get a chance to read from the
standard error stream. As a workaround I use "2>&1" to combine
the streams, but might not always be able to do so easily (e.g.
if I want to redirect the standard output to a file).
2) I have a separate thread which calls destroy() on the Process
after 10 seconds to limit maximum execution time. If I have a
program which runs for 50 seconds, it calls destroy() correctly
after 10 seconds, but the call to waitFor() doesn't complete
until the full 50 seconds have elapsed, and then bad things
start happening (e.g. a database connection gets dropped for
no apparent reason). This is on Windows XP, which may be part
of the problem...
Any ideas?
TIA,
-----------------------------------------------------------------
John English | mailto:[email protected]
Senior Lecturer | http://www.it.bton.ac.uk/staff/je
School of Computing & MIS | ** NON-PROFIT CD FOR CS STUDENTS **
University of Brighton | -- see http://burks.bton.ac.uk
-----------------------------------------------------------------
1) I'm running a program which produces output to both standard
output and standard error streams. How can I read from one or
the other, depending on which has been written to? At the moment
I read from the standard output stream, but this blocks if there
is nothing to be read and I never get a chance to read from the
standard error stream. As a workaround I use "2>&1" to combine
the streams, but might not always be able to do so easily (e.g.
if I want to redirect the standard output to a file).
2) I have a separate thread which calls destroy() on the Process
after 10 seconds to limit maximum execution time. If I have a
program which runs for 50 seconds, it calls destroy() correctly
after 10 seconds, but the call to waitFor() doesn't complete
until the full 50 seconds have elapsed, and then bad things
start happening (e.g. a database connection gets dropped for
no apparent reason). This is on Windows XP, which may be part
of the problem...
Any ideas?
TIA,
-----------------------------------------------------------------
John English | mailto:[email protected]
Senior Lecturer | http://www.it.bton.ac.uk/staff/je
School of Computing & MIS | ** NON-PROFIT CD FOR CS STUDENTS **
University of Brighton | -- see http://burks.bton.ac.uk
-----------------------------------------------------------------