I'm writing a Java object that runs a Perl script. I use the Process
object to do this. I set everything up, then call the waitFor() method
- and the Java program hangs. I've put debug logging into both the
Perl script and the java program, so I see that the Perl script runs
all the way through, but the last thing the Java program does is
execute waitFor().
--
Tim Slattery
Slattery_T@bls.gov
http://members.cox.net/slatteryt
|
|
0
|
|
|
|
Reply
|
Tim
|
12/20/2010 5:51:24 PM |
|
On Mon, 20 Dec 2010, Tim Slattery wrote:
> I'm writing a Java object that runs a Perl script. I use the Process
> object to do this. I set everything up, then call the waitFor() method -
> and the Java program hangs. I've put debug logging into both the Perl
> script and the java program, so I see that the Perl script runs all the
> way through, but the last thing the Java program does is execute
> waitFor().
The most common bug around this sort of thing is that the parent process
doesn't read all the child's output from its standard output stream. The
buffer for the pipe between the two fills up, and the child then gets
blocked waiting for it to empty so that it can finish writing, which of
course never happens because the parent is waiting for the child to
terminate. Deadlock ensues.
However, from what you say, it sounds like the Perl script is terminating.
Is that definitely the case? Could it be that the script finishes running,
but the buffer is never drained, so the Perl interpreter doesn't exit? Can
you see the interpreter in a process listing after the script seems to
have finished? If you drain all the output from the child, does that help?
If not, i'm not sure what to suggest. I note that the javadoc for Process
does mention that:
The methods that create processes may not work well for special processes
on certain native platforms, such as native windowing processes, daemon
processes, Win16/DOS processes on Microsoft Windows, or shell scripts.
So if a Perl script is like a shell script (and it is - albeit a hideously
deformed shell script with mutant superpowers), there could be trouble.
That sounds more like arse-covering than a genuine warning, though.
tom
--
Damn the Solar System. Bad light; planets too distant; pestered with
comets; feeble contrivance; could make a better myself. -- Francis Jeffery
|
|
0
|
|
|
|
Reply
|
Tom
|
12/20/2010 7:29:08 PM
|
|
On Mon, 20 Dec 2010 12:51:24 -0500, Tim Slattery <Slattery_T@bls.gov>
wrote, quoted or indirectly quoted someone who said :
>I'm writing a Java object that runs a Perl script. I use the Process
>object to do this. I set everything up, then call the waitFor() method
>- and the Java program hangs. I've put debug logging into both the
>Perl script and the java program, so I see that the Perl script runs
>all the way through, but the last thing the Java program does is
>execute waitFor().
see http://mindprod.com/jgloss/exec.html
for the usual pitfalls. If your script is eating or producing chars
you need threads to deal with them.
--
Roedy Green Canadian Mind Products
http://mindprod.com
A short order cook is a master of multitasking. Every movement is
optimised from years of practice. Yet when a computer executes a
multitasking program, it approaches the task as if for the first time.
|
|
0
|
|
|
|
Reply
|
Roedy
|
12/20/2010 8:24:10 PM
|
|
Tom Anderson <twic@urchin.earth.li> wrote:
>On Mon, 20 Dec 2010, Tim Slattery wrote:
>
>> I'm writing a Java object that runs a Perl script. I use the Process
>> object to do this. I set everything up, then call the waitFor() method -
>> and the Java program hangs. I've put debug logging into both the Perl
>> script and the java program, so I see that the Perl script runs all the
>> way through, but the last thing the Java program does is execute
>> waitFor().
>
>The most common bug around this sort of thing is that the parent process
>doesn't read all the child's output from its standard output stream. The
>buffer for the pipe between the two fills up, and the child then gets
>blocked waiting for it to empty so that it can finish writing, which of
>course never happens because the parent is waiting for the child to
>terminate. Deadlock ensues.
>
>However, from what you say, it sounds like the Perl script is terminating.
>Is that definitely the case? Could it be that the script finishes running,
>but the buffer is never drained, so the Perl interpreter doesn't exit?
I guess it was something like that. Putting the processes to read
STDOUT and STDERR in separate threads did the trick. But the Perl
script definitely finished, so ?????
--
Tim Slattery
Slattery_T@bls.gov
http://members.cox.net/slatteryt
|
|
0
|
|
|
|
Reply
|
Tim
|
12/20/2010 9:10:16 PM
|
|
On 12/20/2010 1:10 PM, Tim Slattery wrote:
> I guess it was something like that. Putting the processes to read
> STDOUT and STDERR in separate threads did the trick. But the Perl
> script definitely finished, so ?????
I don't know if this is documented somewhere but it's well known. For
whatever reason, Process doesn't consider the process to be "done" until
all of it's output is read. Possibly to avoid issues where one thread
is still reading/processing output and another thread thinks otherwise.
|
|
0
|
|
|
|
Reply
|
markspace
|
12/20/2010 10:16:24 PM
|
|
Tim Slattery <Slattery_T@bls.gov> writes:
> Tom Anderson <twic@urchin.earth.li> wrote:
>
>>On Mon, 20 Dec 2010, Tim Slattery wrote:
>>
>>> I'm writing a Java object that runs a Perl script. I use the Process
>>> object to do this. I set everything up, then call the waitFor() method -
>>> and the Java program hangs. I've put debug logging into both the Perl
>>> script and the java program, so I see that the Perl script runs all the
>>> way through, but the last thing the Java program does is execute
>>> waitFor().
>>
>>The most common bug around this sort of thing is that the parent process
>>doesn't read all the child's output from its standard output stream. The
>>buffer for the pipe between the two fills up, and the child then gets
>>blocked waiting for it to empty so that it can finish writing, which of
>>course never happens because the parent is waiting for the child to
>>terminate. Deadlock ensues.
>>
>>However, from what you say, it sounds like the Perl script is terminating.
>>Is that definitely the case? Could it be that the script finishes running,
>>but the buffer is never drained, so the Perl interpreter doesn't exit?
>
> I guess it was something like that. Putting the processes to read
> STDOUT and STDERR in separate threads did the trick. But the Perl
> script definitely finished, so ?????
The Perl interpreter is written in C, so it probably ends by calling
exit(). One of the things exit() does is to flush all open buffered
output streams. If any of those is a pipe, it could block at that
point.
--
Jim Janney
|
|
0
|
|
|
|
Reply
|
Jim
|
12/20/2010 11:19:02 PM
|
|
On 21/12/2010 9:16 AM, markspace wrote:
> For whatever reason, Process doesn't consider the process to be "done" until
> all of it's output is read.
This is not so. The issue is that the child process can't exit if it is
blocked doing output because the reading end hasn't read it. Process
itself couldn't care less.
|
|
0
|
|
|
|
Reply
|
Esmond
|
12/21/2010 1:43:43 AM
|
|
|
6 Replies
150 Views
(page loaded in 0.148 seconds)
Similiar Articles: Need help with SAS X command to restart to SAS Object Spawner in a ...Hi, I am trying to restart the SAS Object Spawner via a SAS Stored Process. If I test this code in Base SAS it works ok but when I use it in a St... segmentation fault when shared object using STL is statically ...I am using GCC 3.3.2, on Solaris 5.8 and I have a shared object using lots of C++ code ... This is probably because doing so you get two c++ runtimes in your process. Pros and Cons of using Radio Waves to identify remote object ...I need to know the pros and cons of using Radio Waves to identify remote object and ... or antenna) to the wavelength you're using. Radio waves are easier to process ... Determine the process ID of a process that created a named object ...Say, if I create a named object like this in one process: CreateEvent(NULL, FALSE, FALSE, _T("MyNamedEvent")); and then open it in another proce... Setting thread priority using ACE - comp.soft-sys.aceHi I have created an object derived from ACE_Task_Base class. When activate() is ... priority using ACE - comp.soft-sys.ace Controlling CPU utilization of a process ... plotting rectangle aroung moving objects - comp.soft-sys.matlab ...... but the problem i don't know anything in simulink...i don't know the process ... real-time object tracking using optical flow / XY coordinates ..... they are like 305.6010 ... Process synchronization for implementing a global lock - comp.unix ...You can make some use of SysV semaphores; which can be when a holding ... Now of course these locks are process wide defined objects and as such are not defined/safe ... Using thread-specific data in shared libraries - comp.programming ...Threads exit, and during the process they'll atomically observe a TSD ... Command to List Contents of Shared Object (.so) Library - comp ... Using thread-specific data in ... linux shared memory synchronization objects - comp.unix.programmer ...Process shared pthread mutexes and posix semaphores are only supported with NPTL ... not on linux ... create a shared memory ... segmentation fault when shared object using ... extract an object from 1 image and display it on top of another ...I have the locations of the pixels of the objects and all objects have been labelled using ... shortcuts to doing this process, however going through this process at ... Job Objects - Microsoft Corporation: Software, Smartphones, Online ...Starting with Windows 8 and Windows Server 2012, an application can use nested jobs to manage a process tree that uses more than one job object. Using Process object - Microsoft Corporation: Software ...Hi and happy easter I've two question about using the Process object to retrieve Process status & performances: 1) the property TotalProcessorTime is the ... 7/28/2012 5:43:41 AM
|