Here is working code. Compiled on QNX using jikes, run with j9.
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class Spawn {
public static void main( String[] args ) {
System.out.println( “Hello World, I am running /bin/ls!” );
try {
Process p = Runtime.getRuntime().exec( “/bin/ls -l /” );
BufferedReader br = new BufferedReader(
new InputStreamReader( p.getInputStream() ) );
// Wait for the process to finish.
p.waitFor();
// Read the process output.
String line;
while( ( line = br.readLine() ) != null )
System.out.println( line );
} catch( java.lang.Exception e ) {
e.printStackTrace();
}
}
}
Compiled with jikes (from http://qnx.wox.org/repository/6.1/) using…
export CLASSPATH=/opt/vame/ive/lib/jclMAX/classes.zip
jikes Spawn.java
Invoked using j9…
j9 -jlc:max -cp:$PWD Spawn
Hope this helps. Note that I am running this on a 6.2 machine using
VAME v1.5.
chris
Peter Graves <pgraves@qnx.com> wrote:
Unfortunatly like a lot of the people posting here I am not much
of a Java expert. Hopefully someone else more Java aware will
step in and be able to lend a hand…
-Peter
James <> james.gappy@hap.com> > wrote:
Hi Peter,
I tried just running the command “ls” and i get the same error message. Do
you know what could be wrong? thanks
james
“James” <> james.gappy@hap.com> > wrote in message
news:a8s4pv$klh$> 1@inn.qnx.com> …
Hello,
I have a java class that uses java.lang.Runtime to start a QNX program.
However, It doesn’t work and just throws the IOException. Does anyone have
java.lang.Runtime experience with executing QNX programs? Here is my code:
Runtime rt = Runtime.getRuntime();
String call = “/usr/bin/program_name”;
try {
Process pr = rt.exec(call);
pr.waitFor();
System.out.println("Process exit code is: " + pr.exitValue());
} catch(IOException e) {
System.err.println(“IOException starting process!”);
} catch(InterruptedException e) {System.err.println(“Interrupted
waiting for process!”);
}
Thanks in advance for your help!
james
\
–
Chris McKillop <cdm@qnx.com> “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/