On Wed, 12 Sep 2007 22:43:55 -0000, Earl Lewis
<earl.lewis.1@gmail.com> wrote, quoted or indirectly quoted someone
who said :
>What I want to do is put a timer in this code that will only allow the
>command to attempt to run for a set amount of time, and when that time
>elapses the program will decide that the command isn't going to work
>and it quits with an error message.
See http://mindprod.com/jgloss/timer.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
> You java gurus probably hate it when a posting starts like this, but
> here goes anyway. Sorry, in advance!
[quoted text clipped - 119 lines]
>
> Earl
I believe there is a flaw in the logic in the above program.
You call Process.waitFor() before you start the threads which read the process's
standard output/error channels. If the process generates a lot of output, such
that either the output or error channel fills and blocks the process, the
waitFor() will not return. The threads to read that output, which should
prevent the process from blocking, haven't been started yet. Start the threads
to read the process output *before* you invoke Process.waitFor().
This may prevent you from needing to terminate if the process doesn't complete
in a fixed time.

Signature
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
Earl Lewis - 13 Sep 2007 15:49 GMT
> > You java gurus probably hate it when a posting starts like this, but
> > here goes anyway. Sorry, in advance!
[quoted text clipped - 137 lines]
> E-mail : n...@ion.le.ac.uk
> Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
You may well be right. I can tell you that the code 'works' for the
requirements I've had
to date. Up to this point I've only used this for OS commands that
return some sort of
output almost immediately. Now I'm trying to use it to execute a
ping. For security reasons
many hosts are disallowing ping/icmp and subsequently ping will just
sit there waiting for
a reply. That's why I need to only allow this to run for some fixed
period of time before
it is forcibly terminated and returns an error.
I'll try your suggestion and see if I can get the results I want.
Thanks.
Earl
Gordon Beaton - 13 Sep 2007 16:03 GMT
> Now I'm trying to use it to execute a ping. For security reasons
> many hosts are disallowing ping/icmp and subsequently ping will just
> sit there waiting for a reply. That's why I need to only allow this
> to run for some fixed period of time before it is forcibly
> terminated and returns an error.
Perhaps the easiest solution in this case would be to specify a
timeout as part of the ping command itself (read the documentation).
Exactly how does disallowing icmp improve security?
/gordon
--