Reputation: 6690
When I execute the following command in the terminal, it executes as expected i.e. it displays the current folder contents.
echo <password> | sudo -u root -S ls
But if i execute the same command in my java application, its output is:
<password> | sudo -u root -S ls
How do I overcome this?
Upvotes: 1
Views: 138
Reputation: 1580
When you execute it in the shell, the shell splits the command line according to normal shell rules, i.e. you get "execute echo
with parameter <password>
, pipe the result to sudo
...".
Java doesn't use the shell, so you're getting "execute echo
with parameter <password> | sudo -u root -S ls
".
Upvotes: 2