Re: how am I hosing this Process?

Hendrik Schreiber <hs-doAduxQln/dWk0Htik3J/[email protected]>
Newsgroups gmane.org.user-groups.trijug.juglist
Message-ID <[email protected]>
You might want to drain both the inputstream and the errorstream with  
StreamPumpers (i.e. have separate threads read from the two streams).
http://src.opensolaris.org/source/xref/sfw/usr/src/cmd/ant/apache- 
ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/Exec.java might give  
you some hints.

-hendrik

tagtraum industries incorporated
1412 Glenwood Ave 1B
Raleigh, NC 27605
USA
http://www.tagtraum.com/
http://www.beatunes.com/

On Feb 13, 2007, at 4:06 , Thomas L Roche wrote:

> I'm trying to run a bash script from Java in order to run it under
> JUnitPerf, but am failing miserably. Any suggestions about what I'm
> missing? except chops :-(
>
> I've called scripts from Java before, but not for awhile (i.e. back in
> the Runtime.exec days). Process/Builder looked like the way to go, so
> I coded up something like
>
>   public static void execute(List<String> l) throws RunnerException {
>     Process p = null;
>     ProcessBuilder pb = new ProcessBuilder(l);
>     String argsMsg = "\"" + Utils.list2String(l) + "\"";
>     // start debugging
>     Utils.logInfo("start output from " + argsMsg + ":");
>     Utils.logEnvironment(pb);
>     // end debugging
>     try {
>       p = pb.start();
>     } catch (IOException e) {
>       String errmsg = "Failed to run command=" + argsMsg;
>       throw new RunnerException(errmsg, e);
>     }
>     InputStream is = p.getInputStream();
>     InputStreamReader isr = new InputStreamReader(is);
>     BufferedReader br = new BufferedReader(isr);
>     String line;
>     try {
>       while ((line = br.readLine()) != null) {
>         Utils.logInfo(line);
>       }
>     } catch (IOException e) {
>       String errmsg = "Dropped output line from process";
>       throw new RunnerException(errmsg, e);
>     }
>     // start debugging
>     Utils.logInfo("end output from " + argsMsg);
>     // end debugging
>   }
>
> but nothing's happening ... except the logging above. From that I can
> tell that I'm calling the correct command line (i.e. argsMsg has the
> expected value, with a fully-qualified executable and all the
> arguments) and I've got a correct environment. But when I call the
> command from an xterm (FWIW I'm running on linux) Stuff Actually
> Happens (notably files get created in a directory, and a whole lot
> more logging happens); when I call the java app, nothing actually
> happens except the logging above. I.e. I get
>
> - start output from "<correct commandline/>":
> - start environment:
> <correct environment/>
> - end environment.
> - end output from "<correct commandline/>"
>
> when I should instead get
>
> + start output from "<correct commandline/>":
> + start environment:
> <correct environment/>
> + end environment.
> <LOTS MORE STUFF HERE/>
> + end output from "<correct commandline/>"
>
> plus lots of files in the output directory.
>
>
> _______________________________________________
> Juglist mailing list
> [email protected]
> http://trijug.org/mailman/listinfo/juglist_trijug.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.