| Author |
Wrapper application cannot execute scripts properly
|
Nikolay Tsonkov
Greenhorn
Joined: May 31, 2008
Posts: 19
|
|
I hope I'm posting to the right forum thread... My case is that I'm implementing a wrapper application that should start certain batch files in Windows periodically. The wrapper is implemented in C language and is triggered by a Java Servlet in a JBoss Server. The wrapper is started as a process in the Servlet:
The problem is that the wrapper application starts running and executes the provided batch script file periodically but it does nothing... After some investigation I found out that there are some echo statements in the scripts (which is absolutely normal) and after the first echo statement nothing is executing. If I start the same wrapper application in a standalone Java class (apart from the JBoss server) everything is working as expected.
As a workaround I can redirect the output from the echo statements into a log file. But I still don't get why the wrapper application works correct when triggered from the standalone Java application. Does the Servlet bind somehow the wrapper process to the JBoss server process?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 26720
|
|
|
How are you emptying the error and output streams from that Process? You should look up the ProcessBuilder class, and the classic article by Michael Daconta, which you might find a link to here.
|
 |
Nikolay Tsonkov
Greenhorn
Joined: May 31, 2008
Posts: 19
|
|
|
Thank you for the advice - you are right, the process output streams should be handled. But if I have to do this in the Java application I should make a separate thread to get the output from the process streams. However this thread would be bound to the JVM of the JBoss server which is not desired in my case (one of the called batch scripts actually restarts the server and this would kill the thread or whatsoever Java approach handling any output streams). But I found a much simpler and practical approach - the output would be handled in the very wrapper application - the C program would redirect the output from the executed command when it's called to a provided log file (just by using >> operator).
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 26720
|
|
|
That sounds a good idea. Does it work?
|
 |
Nikolay Tsonkov
Greenhorn
Joined: May 31, 2008
Posts: 19
|
|
Yes, it does work. But another issue occurs. The wrapper application is running constantly and outputting to the correct log file. When the JBoss server is shut down (the one that triggered the wrapper) I'm trying to delete all files from the server folder and only one file cannot be deleted - gc.log - and Windows tells me that the file is used by the wrapper application. The application does not use this file for sure - it is placed in a separate folder and the output file too. I guess that the garbage collector of the server is somehow connected to the output stream redirection (despite the server's JVM is dead). I'll keep investigating
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 26720
|
|
Don’t know. Sorry.
Anybody else?
|
 |
 |
|
|
subject: Wrapper application cannot execute scripts properly
|
|
|