Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Re: Why does this only work when I am running a shellscript (http://www.velocityreviews.com/forums/t959214-re-why-does-this-only-work-when-i-am-running-a-shellscript.html)

Steven Simpson 03-30-2013 04:13 PM

Re: Why does this only work when I am running a shellscript
 
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



All times are GMT. The time now is 02:05 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.