• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic