views:

871

answers:

3

I'm running Hudson as a windows service through Tomcat, with no slaves involved. The last build step in the job is a batch file that invokes some Java code. The code uses PostgreSQL's command line tool psql (via Runtime.exec()) to create a database on the local machine and eventually run some tests against it.

The job will progress to this point, then hang indefinitely without starting to create the database. If I run the batch file from the command line, it works perfectly. I don't think http://hudson.gotdns.com/wiki/display/HUDSON/Spawning+processes+from+build applies, since the process spawned doesn't even seem to begin executing, but I'm new to this so please let me know if I'm wrong.

Edit @anjanb: The batch file's only purpose is to invoke the Java code, and the only user input is being passed in as command line arguments, which I can see are going in directly via the build's console output.

Process Explorer is showing that psql is being started, but it's obviously not being executed, since the first command psql is given is to create a new database, but that's not happening.

Edit 2: I've gotten some tips from the Hudson users mailing list, I'll try them out on Monday and report back.

Edit 3: The Java code was already consuming the output streams, I used that article when developing the code. I can't figure out what's going on, so I'm redeveloping the code to use JDBC to create the database, instead of relying on psql and Runtime.exec()

A: 

There is a possibility that the program is waiting on some user input. If the service is not configured to accept user input, it will appear to be hanging.

YOu can try by configuring the service to allow USER INPUT(GUI) -- that might help.

Also, you could run Sysinternals ProcessExplorer and ProcessMonitor -- they will be able to find out where the .BAT job has stopped.

anjanb
+2  A: 

Do you read the output of the process ? If it produces more output than the OS buffers can handle, you need to read it...

Also, some processes wait until input has completed. Try to call process.getInputStream().close() after starting the process.

Maybe this article is also interesting. It's called "When Runtime.exec() won't": http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=2

Tom
That's a great resource, I used it when writing the code itself. It was hanging, but it at least started creating the DB, unlike now.
rjohnston
A: 

Agree with the recco for the Javaworld article.

Which method are you using for exec()? Sometimes I've had problems with environment properties. Are you logging the output stream to see if that gives you any clues?