LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-07-2015, 11:46 AM   #1
Cenzoooo
LQ Newbie
 
Registered: Jul 2015
Posts: 2

Rep: Reputation: Disabled
Talking Help with python scripting (newbie level)


Hello! Im newbie at Python and i need help! Please take a look of example of my script and tell me what i did wrong.

from os import popen
from sys import argv
from subprocess import Popen, PIPE

string = Popen(['arg1', 'arg2', 'arg3'...], stdin=PIPE, stdout=PIPE)

if "ABCD" in string: print "1"
else: print "0"

So the script should enter command with arg1,2,3 and output shoud have lot of informations, and in those informations it should include string "ABCD", so i want this... IF string "ABCD" is found print 1, else print 0.

I get error:
TypeError: argument of type 'Popen' is not iterable

I would really appreciate your help!
Thanks in advance
 
Old 07-07-2015, 11:52 AM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,242

Rep: Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322
Don't use POpen. Use subprocess.check_output.
 
Old 07-07-2015, 12:03 PM   #3
Cenzoooo
LQ Newbie
 
Registered: Jul 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Wow, that was easy, i did that and it works! Thank you very much
 
Old 07-07-2015, 01:41 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Please mark this thread as solved using the thread tools right above your first post.
For the future, when posting code please use code-tags to enclose that code. This will preserve formatting (especially important for Python code) and makes your posts much easier to read.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Python Faceplant - Newbie level help requested Kustom42 Programming 1 07-01-2014 05:42 PM
LXer: Scripting KVM with Python, Part 2: Add a GUI to manage KVM with libvirt and Python LXer Syndicated Linux News 0 01-17-2012 08:11 PM
python: logging can't log info level? Chowroc Programming 2 05-07-2006 03:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration