macron0 has asked for the wisdom of the Perl Monks concerning the following question:
How do I get the output from a sudo command using backticks.
If I do this:
$result=`sudo ls -la`; print "$result\n";
I get the sudo output:
sudo: please use single character options usage: sudo -K | -L | -V | -h | -k | -l | -v usage: sudo [-HPSb] [-p prompt] [-u username|#uid] { -e file [...] | -i | -s | <command> }
If I do this:
$result=`sudo ls -la`; print "$result\n";
I get nothing at all.
It seems such a simple question but I cannot find the answer.
So I was wondering if anyone here might know the answer.
I really need to parse the output of some scripts and I also need to use sudo.
Thank you.
Hans de Groot
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Capture output from backtick commands using sudo
by afoken (Chancellor) on Apr 04, 2010 at 12:06 UTC | |
|
Re: Capture output from backtick commands using sudo
by ww (Archbishop) on Apr 04, 2010 at 12:34 UTC | |
by Anonymous Monk on Oct 03, 2013 at 15:55 UTC | |
by Happy-the-monk (Canon) on Oct 03, 2013 at 16:28 UTC |