Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
jaibhim max wrote:Hi All,
Please guide me to provide password to sudo.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
geek mr wrote:HERE it is. Brace yourself:
echo "password"|sudo -S installer -pkg /YOURDIRECTORY -target /
James Sabre wrote:Don't even think about creating a script that returns the hard coded password using echo. This is insecure.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:It also won't work since the | is a shell tool, and won't be treated as such by Runtime.exec that only can handle single processes, not combined processes like these.
You may be able to use process.getInputStream() and write to that, but I'm not sure.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
James Sabre wrote:
Rob Spoor wrote:It also won't work since the | is a shell tool, and won't be treated as such by Runtime.exec that only can handle single processes, not combined processes like these.
You may be able to use process.getInputStream() and write to that, but I'm not sure.
And even if you get the shell involved by using
it doesn't work in Ubuntu 11.04 or 10.10 since one is still prompted for the password. The problem is that the password has to entered through the 'keyboard' device and not through 'stdin'.
I would be interested to know details of the system "geek mr" used to test this.
geek mr wrote:
James Sabre wrote:
Rob Spoor wrote:It also won't work since the | is a shell tool, and won't be treated as such by Runtime.exec that only can handle single processes, not combined processes like these.
You may be able to use process.getInputStream() and write to that, but I'm not sure.
And even if you get the shell involved by using
it doesn't work in Ubuntu 11.04 or 10.10 since one is still prompted for the password. The problem is that the password has to entered through the 'keyboard' device and not through 'stdin'.
I would be interested to know details of the system "geek mr" used to test this.
I ran this on my mac OS in the command line interface and it ran just fine......I dont know why you guys have trouble running it. I guess, You have to get the shell involved using bash -c when trying to run from java code......just give this command "echo password |sudo -S installer -pkg /YOURDIRECTORY -target / on your command line interface in mac OS....and its gonna run fine.
I understand its not secure but there is no other way to get your work done. So this might well be it.![]()
Rob Spoor wrote:It also won't work since the | is a shell tool, and won't be treated as such by Runtime.exec that only can handle single processes, not combined processes like these.
You may be able to use process.getInputStream() and write to that, but I'm not sure.