[Biojava-l] gromacs shell script
Tamas Horvath
hotafin at gmail.com
Thu Dec 8 09:59:06 EST 2005
On 12/8/05, Tamas Horvath <hotafin at gmail.com> wrote:>> Runtime rtime = Runtime.getRuntime();> Process child = rtime.exec("/bin/sh");>>> BufferedWriter outCommand = new BufferedWriter(new> OutputStreamWriter( child.getOutputStream()));>>> outCommand.write("cd "+workhome +"; chmod +x run.bat;> exit\n");> outCommand.flush();>> child.waitFor();> child.destroy();
this runs well the script gets the executable flag
rtime = Runtime.getRuntime();> child = rtime.exec(workhome+"run.bat");>> BufferedReader input = new BufferedReader(new> InputStreamReader( child.getInputStream()));> BufferedReader inerr = new BufferedReader(new> InputStreamReader(child.getErrorStream()));>> String line = "";String lerr = "";> while ( (line = input.readLine()) != null || (lerr => inerr.readLine()) != null){> if (line != null && !line.equals("")) {> System.out.println(line);> lerr = inerr.readLine();> }> if (lerr != null && !lerr.equals("")) System.out.println> (lerr);> }>> child.waitFor();> System.err.println("EV:"+child.exitValue());> child.destroy();
Here I only get the exit value, and nothing else
On 12/8/05, Thomas Down <td2 at sanger.ac.uk> wrote:>>> On 8 Dec 2005, at 14:16, Tamas Horvath wrote:>> > I know this is not strictly BioJava, but here's my problem:> > I create a shell script file that would run a GROMACS MD> > simulationI generate the necessary input and config files> > I can make the generated shell script runnable> > I cannot actually run the script from the Java application.> > The script works fine from shell...> > The returned exitValue is 255.> > Can anyone tell, what may I do?>> Could you give a few more details about the code you're using to run> the shell script from Java? Running external processes using Java's> Runtime.exec method isn't totally trivial -- you usually need to> start some extra threads to handle the child process' input and output.>> I presume your script is actually printing some kind of error message> to standard error (or maybe standard out, if it's badly behaved, but> these may be getting lost.>> BioJava has some convenience methods that (usually) allow you to run> child processes without writing your own multithreaded code. A> simple usage, that echoes the child's errors and outputs to the> console, would be something like:>> ProcessTools.exec(> new String[] {"/path/to/my/script", "-> someArgument"},> null, // no standard input> new OutputStreamWriter(System.out),> new OutputStreamWriter(System.err)> );>> You probably don't want to do this in production code, but for> development and debugging it's quite useful. For production use,> you'd normally use StringWriters to capture the child process' output.>> Thomas.>
More information about the Biojava-l
mailing list