Making assumptions is the best way to get yourself in trouble…

I found this the hard way. Did you know that the exec method from the Java runtime library forks the external app instead of waiting for its termination? Of course I assumed that it doesnt fork, and it took me ages to figure out that this was exactly the eason why my software was not working. Naturally the API is very clear about this – it actually spells it right out in plain english. I just didnt bother to read it, and assumed that sysadmin is an asshole and he put some kind of upper bound on number of ssh/scp connections…

There is actually no direct way to run a process in a subshel with Java – or at least I don’t think so. The best workaround I found is the waitFor() method from Process class. It will actually stop and wait for the termination of a given process. The same class also has exitValue() which I found extremely usefull way to check if the external app craps out or exits naturally.

Leson learned: do not make assumptions – double check everything, and read API carefully. I could have saved myself a major hedache and considerable amout of time if I havent had assumed that all will work just fine…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: