Re: [Tutor] using subprocess to export files in bash

2012-05-08 Thread Rogelio
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

[Tutor] using subprocess to export files in bash

2012-05-08 Thread Rogelio
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

Re: [Tutor] IPcount = 0 when used with subprocess.call (use something to convert to integer?)

2012-05-07 Thread Rogelio
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

[Tutor] IPcount = 0 when used with subprocess.call (use something to convert to integer?)

2012-05-07 Thread Rogelio
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." **

Re: [Tutor] error when using using subprocess.popen in Python wrapper script

2012-05-07 Thread Rogelio
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

Re: [Tutor] error when using using subprocess.popen in Python wrapper script

2012-05-06 Thread Rogelio
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

[Tutor] error when using using subprocess.popen in Python wrapper script

2012-05-06 Thread Rogelio
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.