• Post Reply Bookmark Topic Watch Topic
  • New Topic

Runtime.exec() not working properly in Linux  RSS feed

 
Chester Caras
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there! I searched the net for Runtime.Exec Problems. I found a lot of forums but there's only 1 forum that i think can help me and that was the thread here with Miss Uma and Frank...Unfortunately, i am not able to understand clearly their conversation.
I've tried modifying the code of my program based on how i understood their conversation in the thread.
Scenario: Im trying to make a system call or run the program "visual" of Som_pak-3.1 using Java in Red Hat Linux version 9 ...
Here are the changes i've done:
Original that I have:
String[] cmd = new String[]{"/bin/sh", "-C", "/root/som_pak-3.1/visual", "-
din", "/root/som_pak-3.1/test"+this.fileNum+".txt", "-cin", "/root/som_pak-
3.1/train.cod", "-dout", "/root/som_pak-3.1/test"+this.fileNum+".vis"};

Process p = Runtime.getRuntime().exec(cmd);
NOT WORKING: NO SUCH METHOD ERROR
Change 1:
String[] cmd = new String[]{"/root/som_pak-3.1/visual", "-din", "/root/som_pak-
3.1/test"+this.fileNum+".txt", "-cin", "/root/som_pak-3.1/train.cod", "-
dout", "/root/som_pak-3.1/test"+this.fileNum+".vis"};
Process p = Runtime.getRuntime().exec(new String [] {"/bin/sh", "cmd"});
NOT WORKING (NO SUCH METHOD ERROR)
Change 2:
String[] cmd = new String[]{"-C", "/root/som_pak-3.1/visual", "-
din", "/root/som_pak-3.1/test"+this.fileNum+".txt", "-cin", "/root/som_pak-
3.1/train.cod", "-dout", "/root/som_pak-3.1/test"+this.fileNum+".vis"};
Process p = Runtime.getRuntime().exec(new String [] {"/bin/sh", "cmd"});
NOT WORKING (NO SUCH METHOD ERROR)
Change 3:
String[] cmd = new String[]{"-C", "/root/som_pak-3.1/", "./visual", "-
din", "/root/som_pak-3.1/test"+this.fileNum+".txt", "-cin", "/root/som_pak-
3.1/train.cod", "-dout", "/root/som_pak-3.1/test"+this.fileNum+".vis"};
Process p = Runtime.getRuntime().exec(new String [] {"/bin/sh", "cmd"});
STILL, NOT WORKING
Change 4:
String[] cmd = new String[]{"./visual", "-din", "/root/som_pak-
3.1/test"+this.fileNum+".txt", "-cin", "/root/som_pak-3.1/train.cod", "-
dout", "/root/som_pak-3.1/test"+this.fileNum+".vis"};
Process p = Runtime.getRuntime().exec(new String [] {"/bin/sh", "cmd"});
NOT WORKING
Change 5:
String[] cmd = new String[]{"-C", "/root/som_pak-3.1/", "./visual", "-
din", "/root/som_pak-3.1/test"+this.fileNum+".txt", "-cin", "/root/som_pak-
3.1/train.cod", "-dout", "/root/som_pak-3.1/test"+this.fileNum+".vis"};
Process p = Runtime.getRuntime().exec(cmd);
ERROR pa rin!
What could be possibly wrong with my code? Can anyone pls help me? I need to clarify this ASAP because the deadline of my thesis is fast approaching. Please? Anyone? Thank you very much!
 
himanshu patel
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the exact error description you are getting and give more
lines of code where you are using Runtime.exec() method?
Just to clarify,
1> Have u checked class path?
2> did you tried running same command manually at linux prompt?
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change 1 - 4 will not work because the command is wrong.
Process p = Runtime.getRuntime().exec(new String [] {"/bin/sh", "cmd"}); Your put double-uote on your variable cmd. Java will interpret as a literal string. So it'll execute /bin/sh/cmd.
Change 5 won't work because you are not calling any command at all.
String[] cmd = new String[]{"-C", "/root/som_pak-3.1/", "./visual", "-
din", "/root/som_pak-3.1/test"+this.fileNum+".txt", "-cin", "/root/som_pak-
3.1/train.cod", "-dout", "/root/som_pak-3.1/test"+this.fileNum+".vis"}; This becomes -C /root/som_pak-3.1/./visual ... what is -C?
Original, just out of curiousity, what is /bin/sh -C? I can't find -C option, I see a -c for bash shell.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!