Can you give a more concrete command/example?
To use subprocess, maybe you can take a look the codes below, I used
as command. it print out the line containing "sys" in my /etc/passwd, also 1 line before and after the matched lines are also printed.
PHP Code:
kent$ python Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess, shlex >>> cmd="grep -E -A1 -B1 sys /etc/passwd" >>> args=shlex.split(cmd) >>> subprocess.Popen(args) <subprocess.Popen object at 0xb753220c> >>> bin:x:2:2:bin:/bin:/bin/sh sys:x:3:3:sys:/dev:/bin/sh sync:x:4:65534:sync:/bin:/bin/sync -- libuuid:x:100:101::/var/lib/libuuid:/bin/sh syslog:x:101:102::/home/syslog:/bin/false klog:x:102:103::/home/klog:/bin/false hplip:x:103:7:HPLIP system user,,,:/var/run/hplip:/bin/false avahi-autoipd:x:104:110:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false
TESTPATH as the name implies is a string containing a path to a binary, it's not a unix command (I wrote it), serviceName,rdir,masterAcct,persona,passwd are variables (strings) like:
rdir = 'hostname.con'
masterAcct = 'guy01'
and so on...
I just managed to get it working like this:
Please advice, should I use SHELL=true or false?
i think shell should be false, if the command ("binary") is in the 1st element of the list. I have ever used a self-written C program as command, it worked. But if you want to run the command in a particular shell, you should set shell=true, and set executable option.
following texts are taken from python doc.
Quote:
The executable argument specifies the program to execute. It is very seldom needed: Usually, the program to execute is defined by the args argument. If shell=True, the executable argument specifies which shell to use. On Unix, the default shell is /bin/sh. On Windows, the default shell is specified by the COMSPEC environment variable. The only reason you would need to specify shell=True on Windows is where the command you wish to execute is actually built in to the shell, eg dir, copy. You don’t need shell=True to run a batch file, nor to run a console-based executable.
So I have this basic script, see below
import subprocess
import shlex
command = "gcloud projects list"
subprocess.check_output(shlex.split(command))
subprocess.check_call(shlex.split(command))
The subprocess.check_call(shlex.split(command)) actually return what I expect. It returns... (6 Replies)
I was wondering is there any occasion where csv module will be desired over pandas. I skipped learning csv module and jumped right into the beautiful pandas and its magical ability to manipulate data. Dataframes are beautiful! (2 Replies)
I have this code that gives this error on Linux and will be grateful if you can help
import rrdtool
try:
ret_asd = rrdtool.update(myfile.rrd,'N:%s:%s' %(metric1, metric2));
except rrdtool.error, e:
print e
When i run the above i get the below error
except... (1 Reply)
Hi guys,
I'm learning python and perl and i was trying to run from python a perl script using the subprocess module.
I have an issue that i don't understand regarding this.
I run this code:
#!/usr/bin/python
import subprocess
p2 = subprocess.Popen(,stdout=subprocess.PIPE)
output2 =... (2 Replies)
Hi,
I am trying to run a shell script using subprocess in python.
I can run simple script with arguments using subprocess.But I am not able to embed xterm in subrocess command.
#!/usr/bin/python
import subprocess
subprocess.call()
Above code gives me error.
Please help me in... (2 Replies)
Hi,
I am trying to multiple urls in multiple tabs within a browser window.
I am using webbrowser module in python:
My code:
import webbrowser
li =
for url in li:
webbrowser.open_new_tab(url)
This code works fine, if the browser is already opened.
If the browser is not started... (5 Replies)
Im planning to automate my testcases. Please suggest me a python module that will ease my automation scripting.
General steps involved in the testcase execution: (all steps below are done in linux machine)
1) start the application under test (AUT)
2) connect to oracle/ms sql db and update... (1 Reply)
When I say "Command Line Interface" I mean the wrapper that allows you to type "commands" and have then correspond to pre-programmed actions... all the while making sure that it looks like you are INSIDE a shell of sorts.
I had good hope for "common.cli" but that didnt last long, when I found... (1 Reply)