• Post Reply Bookmark Topic Watch Topic
  • New Topic

Runtime.getRuntime().exec() not working for me at all...

 
travis woods
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am running tomcat on a linux server (no apache running).
i have a little command called "travis" in /usr/local/bin/test
when i run from linux command prompt... /usr/local/bin/test/travis
it creates a dummy file called travis.log
no big deal, it works fine... i have a JSP page
--------------
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.lang.*" %>
<html>
<head>
</head>
<body>
Just testing script launch.....
<%
Process p = Runtime.getRuntime().exec("usr/local/bin/test/travis");
%>
</body>
</html>
------
does not work... i tried another way by swapping out the coded line with...
Process p = Runtime.getRuntime().exec(new String[] {"/bin/sh", "/usr/local/bin/test/travis"});

still does not work... anyone? please help. this should be easy
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Travis
Try running some other script from the same location and see if that works...
also sometimes if the process output something then we have to do,
BufferedReader br = new BufferedReader(new InputStreamReader(p.getOutputStream()));
and read the output from the process to make it work...
Regards
Maulin
 
Tim Hobbs
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't worked with JSP and Linux, but I do know Linux. Is it perhaps a permissions issue?
 
Mathews P Srampikal
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is working for me.
Process ps=Runtime.getRuntime().exec("/bin/sh runbatch.sh");
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
add p.waitFor();
 
travis woods
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is so frustrating...
it should be simple. i have the directory set to 777 persmissions, so is the file/script. i took all my if/then logic out so ALL the page does is exec the path. the same command inside my "" runs fine from anywhere on the linux command prompt. it doesnt make any sense.
we dont have Apache running on it, just Tomcat standalone... this SHOULD work.... i just pico'd a file and put... " > travis.log" and saved it.. so all the script does and creates a new file, and i cant even get it to work from JSP.
i took the same code and put it in a JSP tag, then made a JSP page with the tag in it, and same result..... does anyone know of anything else?
PS- i did try the /bin/sh and it didnt work...
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you look at the Tomcat's error logs and see if anything meaningful we see there?
Thanks!
Maulin
 
travis woods
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
k, found it. i am just dumb
i wasnt looking in the right file for the output
but now i have a new and unique problem that maybe you guys can help me with... since it's not as dumb as my last problem
i actually need to run the script on machine other than the webserver that im calling it from... its working fine through command line...
from web machine linux prompt i do...
----
ssh machine "/path/to/script"
----
and it works just fine.
in the JSP Page, i do it too, but its not doing anything now... i tried sending it in an array and straight just like above, but i get nothing... has anyone tried this?
my JSP is now the following...
---------------
<%@ page import="java.lang.*" %>
<html>
<head>
</head>
<body>
<%
out.print("Just testing script launch.....???");
//String[] args = new String[] {"ssh","machine","'/path/to/script'"};

Process p = Runtime.getRuntime().exec("ssh machine \"/path/to/script\"");
%>

</body>
</html>
---------
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Travis
Try to add one more level of script. Write one more script say,
executeSSH where you would put this "ssh machine 'scriptpath'" thing and execute that executeSSH script from java.
Here the problem would be- probably we won't be able to get the output from the "ssh machine 'scriptname'" command as it will run as a sub process of the executeSSH script and that might be a problem if we need the output...
Regards
Maulin
 
travis woods
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sounds good. i dont need the output, its being written to a file that I am checking for later.. thanks for all your guys help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!