0

I am trying to execute command using exec method

proc3=Runtime.getRuntime().exec("umount "+m);

Where m is variable having directory location like /mnt, /media When i execute the command in command prompt it will work as expected, but with java exec method it's not working giving exit status 2. What may be the reason ?

3
  • One of the reason for this behaviour is that all the environment variables are not available to the java runtime, as a test can you indentify the absolute path of umount and use it. If that works, the PATH is not available. Commented May 28, 2014 at 10:19
  • You can try calling a script that redirects the error to a file, ie write a shell script which has the command umount $1 > out.log 2> out.err. This way you might be able to catch the error and get an idea of the underlying OS error Commented May 28, 2014 at 10:21
  • the error is you are not root Commented May 28, 2014 at 10:26

2 Answers 2

1

Try with ProcessBuilder :

ProcessBuilder pb = new ProcessBuilder("umount",p1,p2);
pb.start();

You can pass to ProcessBuilder's constructor as many arguments as you want .

PS : Don't forget to check your permission.

Sign up to request clarification or add additional context in comments.

1 Comment

I got to know problem is permission . I must be root user to execute the command. But servlet will run as nobody user
0

You have two option with you. 1) To start your server/servlet using su(not an ideal option). 2) Provide sudo access on umount to the user starting the servlet service, so that it can execute (might need a password). You might have to check this.

Steps to Identify the error: Write a shell script which has the command umount $1 > out.log 2> out.err. This will log any OS error onto a file which enables further debug.

1 Comment

I solved this problem by creating small c++ program to execute the command and providing sticky bit to that program.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.