Strange problem with using getRuntime.exec() in Frames

R

Rohit Gupta

I am having problem over and over again using it.
This time I cant even figure out whats the problem.
I am using getRuntime().exec() to run another java program( say p1) on
a button click in JFrames, it was working fine. I made some changes in
p1 after that and then compiled the code, now when I am again trying to
press the button to execute the file nothing is happening. Its not
executing. I wrote following lines of code to see what I am getting as
output after executing:

Process p=Runtime.getRuntime().exec(execute);
BufferedReader br=new BufferedReader(new
InputStreamReader(p.getInputStream()));
String line;
while((line=br.readLine())!=null)
{
System.out.println(line);
}

still I get nothing, I am not getting any clue as to what is happening.
A particular piece of code which was once working is not working now.
Where does the problem lie, any help would be highly appreciated...

Rohit Gupta
 
J

Johan Poppe

Rohit Gupta wote:
I am having problem over and over again using it.
This time I cant even figure out whats the problem.
I am using getRuntime().exec() to run another java program( say p1) on
a button click in JFrames, it was working fine. I made some changes in
p1 after that and then compiled the code, now when I am again trying to
press the button to execute the file nothing is happening. Its not
executing.

Do you know that p1 works as it should after the modifications? Have
you tried running it by it self?
I wrote following lines of code to see what I am getting as
output after executing:

Process p=Runtime.getRuntime().exec(execute);
BufferedReader br=new BufferedReader(new
InputStreamReader(p.getInputStream()));
String line;
while((line=br.readLine())!=null)
{
System.out.println(line);
}

Try reading the error stream as well.

And print out the command string to verify it.
 
R

Rohit Gupta

yeah p1 works as it should have been after modifications, I tried
running it by itself.
I get the following output on reading the errorstream:

Exception in thread "main" java.lang.NoClassDefFoundError: while
resolving class: hinuri1
at java.lang.VMClassLoader.resolveClass(java.lang.Class)
(/usr/lib64/libgcj.so.5.0.0)
at java.lang.Class.initializeClass() (/usr/lib64/libgcj.so.5.0.0)
at java.lang.Class.forName(java.lang.String, boolean,
java.lang.ClassLoader) (/usr/lib64/libgcj.so.5.0.0)
at gnu.gcj.runtime.FirstThread.run() (/usr/lib64/libgcj.so.5.0.0)
at _Jv_ThreadRun(java.lang.Thread) (/usr/lib64/libgcj.so.5.0.0)
at _Jv_RunMain(java.lang.Class, byte const, int, byte const,
boolean) (/usr/lib64/libgcj.so.5.0.0)
at __gcj_personality_v0
(/misc/fs11/bt2003/rohitg/InputPanel/java.home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre)
at __libc_start_main (/lib64/tls/libc-2.3.3.so)
at _Jv_RegisterClasses
(/misc/fs11/bt2003/rohitg/InputPanel/java.home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre)
Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder
not found in [file:/usr/share/java/libgcj-3.4.2.jar, file:./, core:/]
at java.net.URLClassLoader.findClass(java.lang.String)
(/usr/lib64/libgcj.so.5.0.0)
at gnu.gcj.runtime.VMClassLoader.findClass(java.lang.String)
(/usr/lib64/libgcj.so.5.0.0)
at java.lang.ClassLoader.loadClass(java.lang.String, boolean)
(/usr/lib64/libgcj.so.5.0.0)
at _Jv_FindClass(_Jv_Utf8Const, java.lang.ClassLoader)
(/usr/lib64/libgcj.so.5.0.0)
at java.lang.Class.forName(java.lang.String, boolean,
java.lang.ClassLoader) (/usr/lib64/libgcj.so.5.0.0)
at _Jv_BytecodeVerifier.verify_instructions_0()
(/usr/lib64/libgcj.so.5.0.0)
at _Jv_VerifyMethod(_Jv_InterpMethod) (/usr/lib64/libgcj.so.5.0.0)
at _Jv_PrepareClass(java.lang.Class) (/usr/lib64/libgcj.so.5.0.0)
at _Jv_WaitForState(java.lang.Class, int)
(/usr/lib64/libgcj.so.5.0.0)
at java.lang.VMClassLoader.linkClass0(java.lang.Class)
(/usr/lib64/libgcj.so.5.0.0)
at java.lang.VMClassLoader.resolveClass(java.lang.Class)
(/usr/lib64/libgcj.so.5.0.0)
...8 more


hinuri1 is p1.
I have both the files( java and class file) placed in the correct
location, so why is it showing NoClassDefFoundError...
I printed out the execute string and it is fine, as it should be...


Rohit Gupta
 
R

Raymond DeCampo

Rohit said:
I am having problem over and over again using it.
This time I cant even figure out whats the problem.
I am using getRuntime().exec() to run another java program( say p1) on
a button click in JFrames, it was working fine. I made some changes in
p1 after that and then compiled the code, now when I am again trying to
press the button to execute the file nothing is happening. Its not
executing. I wrote following lines of code to see what I am getting as
output after executing:

Process p=Runtime.getRuntime().exec(execute);
BufferedReader br=new BufferedReader(new
InputStreamReader(p.getInputStream()));
String line;
while((line=br.readLine())!=null)
{
System.out.println(line);
}

still I get nothing, I am not getting any clue as to what is happening.
A particular piece of code which was once working is not working now.
Where does the problem lie, any help would be highly appreciated...

Well, for starters it is probably in the areas that you changed which
I'm gathering is not the above snippet.

Try to write a SSCCE that exhibits the issue and post it here.

HTH,
Ray
 
R

Rohit Gupta

just to add( maybe that would help).....I had made the whole thing in
netbeans, and now when I am running the same thing on windows its
working perfectly fine. I am more perplexed now....where does the
problem lie and how to get rid of it......why isnt it working on linux.
It was working on both the platforms before the modification.
plz help, I need to get it working on both the platforms....

Rohit Gupta

ps: I had copied the modified project in windows( on a different comp.)
and ran it, it wasnt there previously.
 
J

Johan Poppe

Rohit said:
yeah p1 works as it should have been after modifications, I tried
running it by itself.
I get the following output on reading the errorstream:

Exception in thread "main" java.lang.NoClassDefFoundError: while
resolving class: hinuri1 ....
Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder
not found in [file:/usr/share/java/libgcj-3.4.2.jar, file:./, core:/]
at java.net.URLClassLoader.findClass(java.lang.String)
....

This looks like a classpath problem to me. It seems that you get
different settings for the JVM when you run it with exec from another
JVM instance than when you run from the command line. I am not sure
whether it's the class 'hinuri1' or 'java.lang.StringBuilder' it can't
find, though. Note that StringBuilder is a new class in java2 SE 5.0,
it could be that for some reason you end up with an older jvm when you
exec. (You could try to exec "java -version")
hinuri1 is p1.

By the way, it's a very common convention in Java to capitalize class
names, i.e. the class should be called Hinuri1 and not hinuri1.
 
R

Rohit Gupta

It was working fine before...means I just made trivial changes in the
p1 file, that of changing the file name which it produced as output and
then its not working. Before that it was fine. The java version which I
am using is jdk1.5 which comes with netbeans4.0. When I am using it on
a diff machine with identical settings its working. The problem caused
hardly seem to be due to the changes made because that would not affect
the execution of the program and else wise also its getting executed on
the terminal. Is it that the some previous classes present are not
getting modified after making the changes so its causing some sort of
conflict or so, I dont know what is happening...feeling helpless now.
 
R

Roedy Green

I am using getRuntime().exec() to run another java program( say p1) on
a button click in JFrames, it was working fine.

You realise you are not allowed to use exec in unsigned Applets.

Does any message show up on the console?

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
R

Roedy Green

It was working fine before...means I just made trivial changes in the
p1 file, that of changing the file name which it produced as output and
then its not working. Before that it was fine.

See http://mindprod.com/jgloss/dependencies.html

Make sure every class you need is in the jar.

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
R

Rohit Gupta

Ya, every class is present in the jar. I checked it.

I had previously used JApplets but because of the security problem I
had to resort to JFrames.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top