N
Nicki
Gast
Hallo!
Ich versuche gerade ein Perl Skript aus einem java Programm auszuführen. Das Ganze funktioniert auch, wenn ich es mit anderen Programmen ausprobiere, aber beim Perl Skript hängt es bei proc.waitFor(). Muss ich das irgendwie anders aufrufen? Von der Konsole funktioniert der Befehl so.
Ach ja, ich arbeite unter Linux!
Danke,
Nicole
Ich versuche gerade ein Perl Skript aus einem java Programm auszuführen. Das Ganze funktioniert auch, wenn ich es mit anderen Programmen ausprobiere, aber beim Perl Skript hängt es bei proc.waitFor(). Muss ich das irgendwie anders aufrufen? Von der Konsole funktioniert der Befehl so.
Code:
class StreamGobbler extends Thread
{
InputStream is;
String type;
StreamGobbler(InputStream is, String type)
{
this.is = is;
this.type = type;
}
public void run()
{
try
{
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
System.out.println(type + ">" + line);
} catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
public class Exec
{
public static void main(String args[])
{
try
{
String osName = System.getProperty("os.name" );
String cmd = "PLD.pl <atpA.aln >atpA.nexus";
Runtime rt = Runtime.getRuntime();
System.out.println("Execing " + cmd);
Process proc = rt.exec(cmd);
// any error message?
StreamGobbler errorGobbler = new
StreamGobbler(proc.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(proc.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
// any error???
int exitVal = proc.waitFor();
System.out.println("ExitValue: " + exitVal);
} catch (Throwable t)
{
t.printStackTrace();
}
}
}
Ach ja, ich arbeite unter Linux!
Danke,
Nicole