This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to interactive with the process generated by Runtime.getRuntime().exec() on Linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to interactive with the process generated by Runtime.getRuntime().exec() on Linux" Watch "How to interactive with the process generated by Runtime.getRuntime().exec() on Linux" New topic
Author

How to interactive with the process generated by Runtime.getRuntime().exec() on Linux

Zhishan li
Greenhorn

Joined: Dec 05, 2012
Posts: 1
My scenario is:
The shell command "sudo xxx" should be run by Runtime.getRuntime().exec() on linux.
It should wait for entering the password, but it not. And the command fails to executed.

So could you tell me how to upload my password to the process by Java??


I have the idea to enter the passwd by changing the shell command, like this "echo passwd | sudo xxx".
Or create a no passwd account. But I need the password entered by Java function.

Do me a favor. Thanks
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Hello Zhishan and welcome to the Ranch! First and most important, are you familiar with situations When Runtime.exec() won't? If not, be sure to read all four parts of that article and apply the advice you find there.

You will need the -S flag to tell sudo to read its password from stdin.

Apply that, and if you still have problems then post your code in the form of a SSCCE (Short, Self Contained, Correct (Compilable), Example).


luck, db
There are no new questions, but there may be new answers.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
And welcome to the Ranch
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1035
    
  10

You can also use gksudo rather than sudo then a password prompt will be displayed. I would also re-enforce Darryl's advice and say it is very very important that you read ALL the sections of the 'traps' article and implement ALL the recommendations. Failure to do so will just cause you grief.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to interactive with the process generated by Runtime.getRuntime().exec() on Linux
 
Similar Threads
Open a command prompt using Runtime.getRuntime().exec() and run a jar file
how to provide password to sudo command
Shell Script from JAVA program
How to execute a command from Java in Linux?
Executing Shell command in the same process