• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown

Accesssing the Shell Script from JSP

Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have written a java class that calls an shell script.And in the java class, I am accesing the EXIT value retrured by the shell.I am able to run this from the command prompt succesfully.
But,If once I make an instance of this class in a JSP and invoke the method which actually calls the shell script, my script is not working. It is giving an exit code of 127:indicating the command not found.I am unable to resolve this.
I am using the tomcat web server and running it in Linux platform.I have assigned all the rigths to the file.
Want to know whether tomcat has restriction imposed to call any scripts?

Overall, plz help me out.
I am an newbie in this field.
Thanks in advance!
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Linux/Unix systems have a notion of a search path, which the shells use to find programs when you execute something on the command line (or give a command to run via the java Execute call). It's precisely analogous to the classpath Java uses (in fact that's pretty certainly where the java designers got the idea). It's an environment variable called PATH.
So suppose you've got a shell script called 'foo.sh'. When you type that on the command line it finds the script because the directory the script is in is mentioned in the PATH environment variable.
Now when you try getting tomcat to run the script, lots of things are potentially different. The PATH environment variable might be different. You might be depending on the script being in your current working directory, and tomcat has a different current working directory. Or tomcat might even be running with a different user id, which doesn't have permissions to run the script (or maybe even see the script file at all).
The quickest thing to try is give the fully qualified file name for the file (that is, a name that starts at the root directory /). Once that works, we can discuss how to avoid insisting that the file live in that specific place in the file system.
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
    Bookmark Topic Watch Topic
  • New Topic