java.lang.Runtime.exec to start QNX program with java?

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

Hi,

It works fine for me. Make sure that the application do exist in the right
path and has the right permissions. If so you should see the Process exit
code.If not you will be getting the IOException as mentioned.

Regards,
Rajan


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

Hi,

Lets say i just wanted to open up ped (qnx text editor), this code i have
doesn’t work either. Do you know why? thanks for your help!

Runtime rt = Runtime.getRuntime();
String cmd = “ped”;
try {
Process pro = rt.exec(cmd);
System.out.println("Process exit code is: " + pro.exitValue());
}catch(IOException ioe) {
System.err.println("IOException: " + ioe);
}

When i run this program, i just get the error message:
“IOException: java.io.IOException: Unable to start program”


<rajanr@in.ibm.com> wrote in message news:a8uffb$5in$1@nntp.qnx.com

Hi,

It works fine for me. Make sure that the application do exist in the right
path and has the right permissions. If so you should see the Process exit
code.If not you will be getting the IOException as mentioned.

Regards,
Rajan



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

James <james.gappy@hap.com> wrote:

Hi,

Lets say i just wanted to open up ped (qnx text editor), this code i have
doesn’t work either. Do you know why? thanks for your help!

I’m not a Java programmer…but try:


Runtime rt = Runtime.getRuntime();
String cmd = “ped”;

String cmd = “/usr/photon/bin/ped”;

try {
Process pro = rt.exec(cmd);
System.out.println("Process exit code is: " + pro.exitValue());
}catch(IOException ioe) {
System.err.println("IOException: " + ioe);
}

When i run this program, i just get the error message:
“IOException: java.io.IOException: Unable to start program”

If you just give a command like “ped” by itself, you are depending
(generally) on something else providing a list of places to look
for that executable. In C/C++ that is usually done with an environment
variable called PATH that specifies these things – and whether or not
it is looked at depends on how the actually running of the command
is done. Specifying the complete path should always work. Hopefully
that will be the case for the Java side of things as well.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Hi David,

I tried your advice, but I get the same results. I also tried many other
paths and I get the same thing. but I’ll keep playing with the codee,
thanks!

“David Gibbs” <dagibbs@qnx.com> wrote in message
news:a8v5hd$kcp$3@nntp.qnx.com

James <> james.gappy@hap.com> > wrote:
Hi,

Lets say i just wanted to open up ped (qnx text editor), this code i
have
doesn’t work either. Do you know why? thanks for your help!

I’m not a Java programmer…but try:


Runtime rt = Runtime.getRuntime();
String cmd = “ped”;

String cmd = “/usr/photon/bin/ped”;

try {
Process pro = rt.exec(cmd);
System.out.println("Process exit code is: " +
pro.exitValue());
}catch(IOException ioe) {
System.err.println("IOException: " + ioe);
}

When i run this program, i just get the error message:
“IOException: java.io.IOException: Unable to start program”

If you just give a command like “ped” by itself, you are depending
(generally) on something else providing a list of places to look
for that executable. In C/C++ that is usually done with an environment
variable called PATH that specifies these things – and whether or not
it is looked at depends on how the actually running of the command
is done. Specifying the complete path should always work. Hopefully
that will be the case for the Java side of things as well.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

One thing that may be worth trying is spawning a non photon app (ls for
example) and see if that works. If that works then you may be missing
some enviroment stuff you need for photon (LD_LIBRARY_PATH, PATH, PHOTON).

-Peter

James <james.gappy@hap.com> wrote:

Hi David,

I tried your advice, but I get the same results. I also tried many other
paths and I get the same thing. but I’ll keep playing with the codee,
thanks!

“David Gibbs” <> dagibbs@qnx.com> > wrote in message
news:a8v5hd$kcp$> 3@nntp.qnx.com> …
James <> james.gappy@hap.com> > wrote:
Hi,

Lets say i just wanted to open up ped (qnx text editor), this code i
have
doesn’t work either. Do you know why? thanks for your help!

I’m not a Java programmer…but try:


Runtime rt = Runtime.getRuntime();
String cmd = “ped”;

String cmd = “/usr/photon/bin/ped”;

try {
Process pro = rt.exec(cmd);
System.out.println("Process exit code is: " +
pro.exitValue());
}catch(IOException ioe) {
System.err.println("IOException: " + ioe);
}

When i run this program, i just get the error message:
“IOException: java.io.IOException: Unable to start program”

If you just give a command like “ped” by itself, you are depending
(generally) on something else providing a list of places to look
for that executable. In C/C++ that is usually done with an environment
variable called PATH that specifies these things – and whether or not
it is looked at depends on how the actually running of the command
is done. Specifying the complete path should always work. Hopefully
that will be the case for the Java side of things as well.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

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

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

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/

Hi, I tried running the java class with j9 on QNX, but I still get the same
error message “unable to start program”

Runtime rt = Runtime.getRuntime();
try {
Process pro = rt.exec("/usr/photon/bin/ped");
pro.waitFor(); // wait until it’s done executing
System.out.println("Process exit code is: " + pro.exitValue());
}catch(IOException ioe) {
System.err.println("IOException → " + ioe);
} catch(InterruptedException ie){
System.err.println("InterruptedException: " + ie);
}

I tried this and variations of it so many times, but still doesn’t work.
Anyone know what could be wrong? Thanks so much for all your help!

What version of j9 and what version of QNX?

chris

James <james.gappy@hap.com> wrote:

Hi, I tried running the java class with j9 on QNX, but I still get the same
error message “unable to start program”

Runtime rt = Runtime.getRuntime();
try {
Process pro = rt.exec("/usr/photon/bin/ped");
pro.waitFor(); // wait until it’s done executing
System.out.println("Process exit code is: " + pro.exitValue());
}catch(IOException ioe) {
System.err.println("IOException → " + ioe);
} catch(InterruptedException ie){
System.err.println("InterruptedException: " + ie);
}

I tried this and variations of it so many times, but still doesn’t work.
Anyone know what could be wrong? Thanks so much for all your help!


Chris McKillop <cdm@qnx.com> “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/

I have tried both J9 v 1.4 and 1.5, and QNX RTOS version 6.1


“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

James <james.gappy@hap.com> wrote:

I have tried both J9 v 1.4 and 1.5, and QNX RTOS version 6.1

Curious. Are you doing this on an embedded platform?

chris


“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/

yeah, im trying it out on QNX/SH4 platform.


“Chris McKillop” <cdm@qnx.com> wrote in message
news:a979q7$p0f$1@nntp.qnx.com

James <> james.gappy@hap.com> > wrote:
I have tried both J9 v 1.4 and 1.5, and QNX RTOS version 6.1


Curious. Are you doing this on an embedded platform?

chris



“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/

James <james.gappy@hap.com> wrote:

yeah, im trying it out on QNX/SH4 platform.

Make sure you have a /bin/sh on your target and that the /bin/sh supports
standard shell options. I have a feeling they may be using system() or
something else to setup the environment. Maybe not, but it is worth a try.

chris


Chris McKillop <cdm@qnx.com> “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/

Hi Chris,

I do have a /bin/sh. I tried typing “/bin/sh -c /usr/photon/bin/ped” on the
qnx command line, and that works. However, when i try to execute this
command with my java code, I get the same error message that reads “unable
to start program”. Any clue whats going on? Below is the java class that
I’m using. I really appriciate your help!

public class MyTest {
public static void main(String[] args) throws IOException{
String[] cmd = {"/bin/sh -c /usr/photon/bin/ped"};
//String[] cmd = {"/bin/sh", “-c”, “/usr/photon/bin/ped”};
Runtime rt = Runtime.getRuntime();
try {
file://Process pro = rt.exec("/usr/photon/bin/ped");
Process pro = rt.exec(cmd);
pro.waitFor(); // wait until it’s done executing
System.out.println("Process exit code is: " + pro.exitValue());
}catch(IOException ioe) {
System.err.println("IOException → " + ioe);
} catch(InterruptedException ie){
System.err.println("InterruptedException: " + ie);
}
}
}

You are making your cmd an Array (String[] cmd) and so you are invoking
rt.exec( String[] cmd ), which expects that each argument ends up as
an entry in that array. You have two options to make it work…

o Change the cmd declaration to…

String cmd = “/bin/sh -c /usr/photon/bin/ped”;

o Change the cmd declaration to (which you have commented out)…

String[] cmd = { “/bin/sh”, “-c”, “/usr/photon/bin/ped” };


Also make sure you are using the jclMAX runtime library with j9. You invoke
that by using “j9 -jcl:max …”. I have not been running with any of the
other jcl variants in my tests.

chris


James <james.gappy@hap.com> wrote:

Hi Chris,

I do have a /bin/sh. I tried typing “/bin/sh -c /usr/photon/bin/ped” on the
qnx command line, and that works. However, when i try to execute this
command with my java code, I get the same error message that reads “unable
to start program”. Any clue whats going on? Below is the java class that
I’m using. I really appriciate your help!

public class MyTest {
public static void main(String[] args) throws IOException{
String[] cmd = {"/bin/sh -c /usr/photon/bin/ped"};
//String[] cmd = {"/bin/sh", “-c”, “/usr/photon/bin/ped”};
Runtime rt = Runtime.getRuntime();
try {
file://Process pro = rt.exec("/usr/photon/bin/ped");
Process pro = rt.exec(cmd);
pro.waitFor(); // wait until it’s done executing
System.out.println("Process exit code is: " + pro.exitValue());
}catch(IOException ioe) {
System.err.println("IOException → " + ioe);
} catch(InterruptedException ie){
System.err.println("InterruptedException: " + ie);
}
}
}


Chris McKillop <cdm@qnx.com> “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/

Hi Chris,

I tried what you said, and so many other variations of it, but I still get
that “unable to start program” ioexception message. I am using the jclmax
runtime library for j9 also. On a different program, I am able to read qnx
files using java, but I just can’t seem to get this program to work. I
really appriciate your help, thanks

James


“Chris McKillop” <cdm@qnx.com> wrote in message
news:a9fapp$lg5$1@nntp.qnx.com

You are making your cmd an Array (String[] cmd) and so you are invoking
rt.exec( String[] cmd ), which expects that each argument ends up as
an entry in that array. You have two options to make it work…

o Change the cmd declaration to…

String cmd = “/bin/sh -c /usr/photon/bin/ped”;

o Change the cmd declaration to (which you have commented out)…

String[] cmd = { “/bin/sh”, “-c”, “/usr/photon/bin/ped” };


Also make sure you are using the jclMAX runtime library with j9. You
invoke
that by using “j9 -jcl:max …”. I have not been running with any of the
other jcl variants in my tests.

chris


James <> james.gappy@hap.com> > wrote:
Hi Chris,

I do have a /bin/sh. I tried typing “/bin/sh -c /usr/photon/bin/ped” on
the
qnx command line, and that works. However, when i try to execute this
command with my java code, I get the same error message that reads
“unable
to start program”. Any clue whats going on? Below is the java class
that
I’m using. I really appriciate your help!

public class MyTest {
public static void main(String[] args) throws IOException{
String[] cmd = {"/bin/sh -c /usr/photon/bin/ped"};
file://String[] cmd = {"/bin/sh", “-c”, “/usr/photon/bin/ped”};
Runtime rt = Runtime.getRuntime();
try {
file://Process pro = rt.exec("/usr/photon/bin/ped");
Process pro = rt.exec(cmd);
pro.waitFor(); // wait until it’s done executing
System.out.println("Process exit code is: " +
pro.exitValue());
}catch(IOException ioe) {
System.err.println("IOException → " + ioe);
} catch(InterruptedException ie){
System.err.println("InterruptedException: " + ie);
}
}
}


\

Chris McKillop <> cdm@qnx.com> > “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/

I have to wonder if this isn’t an SH issue. I don’t have an SH system here
so I have been doing all my test on x86. Your code, with the changes I
listed below, works just fine. I would raise this with your support yet.

chris

James <james.gappy@hap.com> wrote:

Hi Chris,

I tried what you said, and so many other variations of it, but I still get
that “unable to start program” ioexception message. I am using the jclmax
runtime library for j9 also. On a different program, I am able to read qnx
files using java, but I just can’t seem to get this program to work. I
really appriciate your help, thanks

James


“Chris McKillop” <> cdm@qnx.com> > wrote in message
news:a9fapp$lg5$> 1@nntp.qnx.com> …

You are making your cmd an Array (String[] cmd) and so you are invoking
rt.exec( String[] cmd ), which expects that each argument ends up as
an entry in that array. You have two options to make it work…

o Change the cmd declaration to…

String cmd = “/bin/sh -c /usr/photon/bin/ped”;

o Change the cmd declaration to (which you have commented out)…

String[] cmd = { “/bin/sh”, “-c”, “/usr/photon/bin/ped” };


Also make sure you are using the jclMAX runtime library with j9. You
invoke
that by using “j9 -jcl:max …”. I have not been running with any of the
other jcl variants in my tests.

chris


James <> james.gappy@hap.com> > wrote:
Hi Chris,

I do have a /bin/sh. I tried typing “/bin/sh -c /usr/photon/bin/ped” on
the
qnx command line, and that works. However, when i try to execute this
command with my java code, I get the same error message that reads
“unable
to start program”. Any clue whats going on? Below is the java class
that
I’m using. I really appriciate your help!

public class MyTest {
public static void main(String[] args) throws IOException{
String[] cmd = {"/bin/sh -c /usr/photon/bin/ped"};
file://String[] cmd = {"/bin/sh", “-c”, “/usr/photon/bin/ped”};
Runtime rt = Runtime.getRuntime();
try {
file://Process pro = rt.exec("/usr/photon/bin/ped");
Process pro = rt.exec(cmd);
pro.waitFor(); // wait until it’s done executing
System.out.println("Process exit code is: " +
pro.exitValue());
}catch(IOException ioe) {
System.err.println("IOException → " + ioe);
} catch(InterruptedException ie){
System.err.println("InterruptedException: " + ie);
}
}
}


\

Chris McKillop <> cdm@qnx.com> > “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/

\


Chris McKillop <cdm@qnx.com> “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/

I still can’t get this to work, i have no idea what’s wrong.


“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