Re: Call a shell command from Python

2016-11-05 Thread Bob Martin
in 767198 20161104 142132 Thomas 'PointedEars' Lahn wrote: >Ben Finney wrote: > >> Note that ‘sudo’ is specifically designed to be invoked interactively, > >Nonsense. > >> seeking to verify that the current user has credentials to run the >> command. > >NOPASSWD is not the default in sudoers(5

Re: Call a shell command from Python

2016-11-01 Thread Wildman via Python-list
On Tue, 01 Nov 2016 11:23:09 -0400, D'Arcy Cain wrote: > On 2016-11-01 01:23 AM, Ben Finney wrote: >> Wildman via Python-list writes: >> So the way your script was invoked has no bearing on whether Bash will >> get involved in what your script does. Your script is *directly* >> invoking programs,

Re: Call a shell command from Python

2016-11-01 Thread D'Arcy Cain
On 2016-11-01 01:23 AM, Ben Finney wrote: Wildman via Python-list writes: So the way your script was invoked has no bearing on whether Bash will get involved in what your script does. Your script is *directly* invoking programs, and if you don't ask for a shell to be involved you won't get it.

Re: Call a shell command from Python

2016-11-01 Thread Wildman via Python-list
On Tue, 01 Nov 2016 13:42:03 +, Grant Edwards wrote: > On 2016-11-01, Steve D'Aprano wrote: >> On Tue, 1 Nov 2016 04:00 pm, Wildman wrote: >> >>> You are correct about that but, in this case grep never "sees" the '$' >>> sign. Bash expands $USER to the actual user name beforehand. If you >>

Re: Call a shell command from Python

2016-11-01 Thread Wildman via Python-list
On Tue, 01 Nov 2016 16:52:18 +1100, Steve D'Aprano wrote: > On Tue, 1 Nov 2016 04:00 pm, Wildman wrote: > >> You are correct about that but, in this case grep never "sees" the '$' >> sign. Bash expands $USER to the actual user name beforehand. If you >> are on a Linux system, enter this into a

Re: Call a shell command from Python

2016-11-01 Thread Wildman via Python-list
On Tue, 01 Nov 2016 16:23:08 +1100, Ben Finney wrote: > Wildman via Python-list writes: > >> […] in this case grep never "sees" the '$' sign. Bash expands $USER to >> the actual user name beforehand. > > I understand how Bash substitutes variables on the command line. > > What I need to repeat

Re: Call a shell command from Python

2016-11-01 Thread Grant Edwards
On 2016-11-01, Steve D'Aprano wrote: > On Tue, 1 Nov 2016 04:00 pm, Wildman wrote: > >> You are correct about that but, in this case grep never "sees" the '$' >> sign. Bash expands $USER to the actual user name beforehand. If you >> are on a Linux system, enter this into a terminal to illustrate

Re: Call a shell command from Python

2016-10-31 Thread Steve D'Aprano
On Tue, 1 Nov 2016 04:00 pm, Wildman wrote: > You are correct about that but, in this case grep never "sees" the '$' > sign. Bash expands $USER to the actual user name beforehand. If you > are on a Linux system, enter this into a terminal to illustrate: > > sudo grep ^$USER\: /etc/shadow Bash

Re: Call a shell command from Python

2016-10-31 Thread Ben Finney
Wildman via Python-list writes: > […] in this case grep never "sees" the '$' sign. Bash expands $USER to > the actual user name beforehand. I understand how Bash substitutes variables on the command line. What I need to repeat, though: In this case, no, Bash doesn't do that because Bash isn't g

Re: Call a shell command from Python

2016-10-31 Thread Wildman via Python-list
On Tue, 01 Nov 2016 12:08:52 +1100, Ben Finney wrote: > Wildman via Python-list writes: > >> On Mon, 31 Oct 2016 15:44:13 +1100, Ben Finney wrote: >> >> > One immediate difference I see is that you specify different >> > arguments to ‘grep’. You have a different pattern for each command. >> > >

Re: Call a shell command from Python

2016-10-31 Thread Ben Finney
Wildman via Python-list writes: > On Mon, 31 Oct 2016 15:44:13 +1100, Ben Finney wrote: > > > One immediate difference I see is that you specify different > > arguments to ‘grep’. You have a different pattern for each command. > > > > * The ‘^user\:’ pattern matches “user\:” at the start of a li

Re: Call a shell command from Python (was: Calling Bash Command From Python)

2016-10-31 Thread Grant Edwards
On 2016-10-31, Wildman via Python-list wrote: > On Mon, 31 Oct 2016 15:44:13 +1100, Ben Finney wrote: >> Wildman via Python-list writes: >> >>> Python 2.7.9 on Linux >>> >>> Here is a bash command that I want to run from a python >>> program: sudo grep "^user\:" /etc/shadow >> >> Some points t

Re: Call a shell command from Python (was: Calling Bash Command From Python)

2016-10-31 Thread Wildman via Python-list
On Mon, 31 Oct 2016 15:44:13 +1100, Ben Finney wrote: > Wildman via Python-list writes: > >> Python 2.7.9 on Linux >> >> Here is a bash command that I want to run from a python >> program: sudo grep "^user\:" /etc/shadow > > Some points to note: > > * Those commands are not special to Bash, o

Re: Call a shell command from Python (was: Calling Bash Command From Python)

2016-10-30 Thread Chris Angelico
On Mon, Oct 31, 2016 at 3:44 PM, Ben Finney wrote: > Note that ‘sudo’ is specifically designed to be invoked interactively, > seeking to verify that the current user has credentials to run the > command. > > Note further that ‘sudo’ will record when the *current user session* > last invoked ‘sudo’

Call a shell command from Python (was: Calling Bash Command From Python)

2016-10-30 Thread Ben Finney
Wildman via Python-list writes: > Python 2.7.9 on Linux > > Here is a bash command that I want to run from a python > program: sudo grep "^user\:" /etc/shadow Some points to note: * Those commands are not special to Bash, or any particular shell. They invoke commands, without AFAIK any speci