NetRock6
asked on
Python: Running sudo
Hi ...
Trying running a python script that calls a bash script as sudo. to get all the standard input/output using the below:
But, if i do the following:
Can someone please help to get the std/stout.
Thanks
Trying running a python script that calls a bash script as sudo. to get all the standard input/output using the below:
sas_cmd = ['sudo', 'apacheart']
proc = subprocess.Popen(sas_cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
it is not calling the script at all ....But, if i do the following:
proc = subprocess.Popen(['sudo','/usr/bin/apacheart'])
It calls the script.Can someone please help to get the std/stout.
Thanks
ASKER
@dfke,
Thanks for your help.
It calls the script but i do not see any stdout.
Any idea why?
Thanks
Thanks for your help.
It calls the script but i do not see any stdout.
Any idea why?
Thanks
Did you print the output variable and see nothing?
ASKER
I print 'rc' and get 0 ...
rc contains the return code which is 0 when the command is successful. You want to print the variable named output if you are using the code that dfke posted above.
ASKER
You mean:
print (output)
print (output)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great dfke. Thanks.
This is what I exactly was looking for. Is there a way to open a shell and direct the outputs in that shell.
Thank you again for your great help.
Cheers
This is what I exactly was looking for. Is there a way to open a shell and direct the outputs in that shell.
Thank you again for your great help.
Cheers
something like:
Open in new window
Cheers