Terminally Incoherent

Utterly random, incoherent and disjointed rants and ramblings...

Sunday, May 09, 2004

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...

0 Comments:

Post a Comment

<< Home