Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Why does this only work when I am running a shellscript

Reply
Thread Tools

Re: Why does this only work when I am running a shellscript

 
 
Steven Simpson
Guest
Posts: n/a
 
      03-30-2013
On 30/03/13 08:46, Cecil Westerhof wrote:
> I have the following code:
> private static void doCommand(final String cmd) throws IOException {
> Process p;
> Scanner sc;
>
> System.out.println("#" + cmd + "#");
> p = Runtime.getRuntime().exec(cmd);
> sc = new Scanner(p.getInputStream());
> while (sc.hasNext()) {
> System.out.println(sc.nextLine());
> }
> }


You should also drain Process.getErrorStream(). You could discard it,
copy it to System.err, log it, buffer it to report only if the command's
exit code is non-zero, ...

Also, if you have no specific stream input for the process, I think it
would be a good idea to close your OutputStream to it, though that
should only matter if the process tries to read its input.

--
ss at comp dot lancs dot ac dot uk

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Why does this only work when I am running a shellscript RVic Java 2 04-01-2013 12:04 AM
Re: Why does this only work when I am running a shellscript Barb Knox Java 1 03-30-2013 04:07 PM
Re: Why does this only work when I am running a shellscript Roedy Green Java 0 03-30-2013 03:35 PM
Re: Why does this only work when I am running a shellscript markspace Java 1 03-30-2013 03:34 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM



Advertisments