Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail From: Steven Simpson Newsgroups: comp.lang.java.programmer Subject: Re: Why does this only work when I am running a shellscript Date: Sat, 30 Mar 2013 16:13:46 +0000 Organization: A noiseless patient Spider Lines: 25 Message-ID: References: <8738vdmg0h.fsf@Servus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: mx05.eternal-september.org; posting-host="7e194865abb1454ff7685570b1bd8709"; logging-data="21418"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1++OeOf1uo2HEobwdK2OC/ttMYGwn4i5sY=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 In-Reply-To: <8738vdmg0h.fsf@Servus.decebal.nl> Cancel-Lock: sha1:spqJ4FYLg9SBQ/3RcBeqdBR+Wmg= Xref: csiph.com comp.lang.java.programmer:23161 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