On Tue, May 8, 2012 at 11:06 AM, David Abbott wrote:
> I have used this before;
>
> def uptime_report():
> """Generate uptime"""
> p = subprocess.Popen("uptime > /tmp/uptime.txt",
> shell=True, stdout=subprocess.PIPE)
> return p.stdout.readlines()
>
> That was from python 2.6
While reading the subprocess documentation, I found a great example on
how to call commands with a PIPE
http://docs.python.org/library/subprocess.html
**
output=`dmesg | grep hda`
# becomes
p1 = Popen(["dmesg"], stdout=PIPE)
p2 = Popen(["grep", "hda"], stdin=p1.stdout, std
On Mon, May 7, 2012 at 8:09 PM, Rogelio wrote:
> Why does IPcount not equal 46? Is this what the stout is for?
FWIW, I think this seems to fix it and make IPcount an integer.
import os
IPcount = os.popen("wc -l file.txt | awk '{print $1}'").read()
print "You have
I am wrapping a Python wrapper script to "wc -l" (count lines) of a
list of IP addresses
***
import subprocess
IPcount = subprocess.call(['wc -l file.txt | awk \'{print $1}\''], shell=True)
print "You have",IPcount,"IP addresses that are alive."
**
If I want to write this command to a file, would this be the right format?
*
import subprocess
(all my variables defined okay)
perl_script=subprocess.call(['perl',perl_prog,ipfile,cmd,user,timeout,])
log=open('/tmp/pythonOutput.txt',w)
log.write(subprocess.call(p
On Sun, May 6, 2012 at 8:23 PM, Martin A. Brown wrote:
> Or, if I were in your shoes, I would do something a bit more like
> this:
>
> cmd = [ '/usr/bin/perl', '/path/to/perlprog.pl', '-h' ]
> subprocess.call(cmd)
Thank you, Martin. This was helpful. Installed Strace and found out
that I mis
I am new to Python and am trying to figure out how to execute Linux
commands via a Python wrapper.
This works
**
#this works okay
import subprocess
uname = "uname"
uname_arg = "-a"
subprocess.call([uname,uname_arg])
**
But this doesn't.