• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problems invoking a shell script from a servlet

 
rahul takkallapally
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am on a unix machine , i have a servlet which is invoked from an applet , this servlet has to invoke a shell script , for invoking the shell script i have written something like this..

void runCommand1() {
try {
//progress1.setText("Start...");
String command = "/usr/filetesting/testing.sh";
Process process = Runtime.getRuntime().exec(command);
InputStream istream = process.getInputStream();
InputStreamReader ireader = new InputStreamReader(istream);
BufferedReader breader = new BufferedReader(ireader);
stringValue1=" testing the end of the runcommand block";
}
catch (IOException e) {
System.out.println("" + e);
stringValue1=e.toString();
}
}
and the shell script has only one command mkdir anirudh
there are no exceptions comming up , nor is the directory being created
please tell me what could i be doing wrong.....
thanks....
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if the command really looks like "mkdir anirudh", then the problem could just be that the current directory isn't whatever you're assuming it to be. There's nothing in your code that would detect whether this mkdir command failed.
The first thing to try: hard code an absolute path like "/tmp/anirudh" into your script and see if that directory appears. If so, then you know the problem is just that the current directory wasn't what you thought it was.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the command is generating an error report it would be on the error stream - you need to provide for reading it also.
Bill
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, you may be creating the directory, but in another location. You can find it by using the unix find command i.e. .
But you probably want to change your shell script to something like this:
or something that returns a message code. This will create the directory only if it doesn't exist, otherwise you will generate an error message if you run mkdir twice and the directory already exists. Then you can check the error stream.
craig.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic