0

I have a servlet running in tomcat6. I use the following code to execute a command in ubuntu Runtime.getRuntime().exec("/usr/bin/wine cmd /c some.vbs"); the problem is tomcat6 runs the programme as "tomcat6" user, the above java command. So the the above commands getErrorStream returns as "wine: /home/randeel/.wine is not owned by you" I have installed "wine" using user "randeel". Is there a workaround for this?

Thank you, Rana.

1
  • 1
    If you do "chmod a+rwx /home/randeel/.wine" it works ? Commented Nov 24, 2010 at 8:53

2 Answers 2

2

Yes: You must switch the user. Try

Runtime.getRuntime().exec("sudo -U randeel /usr/bin/wine cmd /c some.vbs");

Note that sudo will ask for a password unless you configure it otherwise.

Another, more elegant solution, is to run a little server as randeel which waits for a network connection. It then runs the command and returns the output via the network connection. See the documentation for java.net.Socket.

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

2 Comments

hi, when i execute this command"sudo -l -U randeel /usr/bin/wine cmd /c some.vbs" i get the output as text "/usr/bin/wine cmd /c some.vbs" any solution to that? programme didn't run. i changed the sudoers to ask for no passwd.
Try it from the command line first until you get the output you want. Only when that works, try to get the Java code to work.
0

You have 2 solutions. 1. give appropriate execute permissions to wine using chmod a+x. 2. If you do not want to do #1 you have to run command line that first changes the user and then runs the application. command su USERNAME changes current user but requires typing password. To emulate the terminal that types password you can use expect script.

Then you can run command as different user. If you are going to use this way I'd recommend you to write short shell script that does these 2 actions and run this script from java.

The #2 is more complicated. Way #1 seems to be much simpler.

Comments

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.