Python subprocess

A forum for general discussion of the Python programming language.

Python subprocess

Postby capitanui » Wed Oct 23, 2013 11:11 am

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:

Code: Select all
#!/usr/bin/python
import subprocess

p2 = subprocess.Popen(["grep", "print", "first.pl"],stdout=subprocess.PIPE)
output2 = p2.communicate()[0]
print output2

p1 = subprocess.Popen(["perl","first.pl"],stdout=subprocess.PIPE)
output1 = p1.comunicate()[0]
print output1

First part : run grep, works as expected, i can get the ouput and display it.
The second one, when i actually want to run the perl script and get the output throws me an error :

Code: Select all
Traceback (most recent call last):
  File "./test.py", line 9, in ?
    output1 = p1.comunicate()[0]
AttributeError: 'Popen' object has no attribute 'comunicate'


I don't understand why this happens since the code is similar. Can someone enlight me?

Thanks,
Ionut
Last edited by metulburr on Wed Oct 23, 2013 11:14 am, edited 1 time in total.
Reason: lock op
capitanui
 
Posts: 2
Joined: Wed Oct 23, 2013 11:09 am

Re: Python subprocess

Postby metulburr » Wed Oct 23, 2013 11:14 am

AttributeError: 'Popen' object has no attribute 'comunicate'

check the differences between the first and the second communicate()[0] as the first one you spelled correctly and the second one you typo'ed.

Code: Select all
output2 = p2.communicate()[0]


Code: Select all
output1 = p1.comunicate()[0]
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Python subprocess

Postby capitanui » Wed Oct 23, 2013 11:16 am

Oh.. if i hadn't checked the spelling several times:)
Sorry for this stupid question.
Next time i'll be more carefull.
capitanui
 
Posts: 2
Joined: Wed Oct 23, 2013 11:09 am


Return to General Discussions

Who is online

Users browsing this forum: Google Feedfetcher and 5 guests