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 05-26-2010, 03:42 AM   #1
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 657

Rep: Reputation: 40
Python issue: commands.getoutput(command) fails


Hi.

I've writte a small Munin plugin using python, which basically runs a shell command, and write the output to a file. For some reason the script fail quite often, and it seems to be failing at the "commands.getoutput" statement. This is what's leading up to that statement:
Code:
varA = someString[0:11] 
command = "/bin/grep \"%s\" /path/to/file.txt|wc -l" % varA 
command_output = commands.getoutput(command)
I've added some debugging statements writing the "command" variable to file, and the doesn't seem to be anything wrong with the command itself. But for some reason things fail. Any ideas on how to debug this?


- kenneho
 
Old 05-26-2010, 04:03 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by kenneho View Post
Hi.

I've writte a small Munin plugin using python, which basically runs a shell command, and write the output to a file. For some reason the script fail quite often, and it seems to be failing at the "commands.getoutput" statement. This is what's leading up to that statement:
Code:
varA = someString[0:11] 
command = "/bin/grep \"%s\" /path/to/file.txt|wc -l" % varA 
command_output = commands.getoutput(command)
I've added some debugging statements writing the "command" variable to file, and the doesn't seem to be anything wrong with the command itself. But for some reason things fail. Any ideas on how to debug this?


- kenneho
Python does have regular expressions, doesn't it ? So why spawning processes using 'grep', 'wc' in the first place ?
 
Old 05-26-2010, 06:58 AM   #3
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 657

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by Sergei Steshenko View Post
Python does have regular expressions, doesn't it ? So why spawning processes using 'grep', 'wc' in the first place ?
I didn't know that. This is my first python script, so I'm still learning. I'll check out regexps!
 
Old 05-26-2010, 10:37 AM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by kenneho View Post
I didn't know that. This is my first python script, so I'm still learning. I'll check out regexps!
AFAIK, there is a separate module implementing regular expressions. I am not a Python guy, so I can't be more specific off the top of my head.
 
Old 05-26-2010, 02:49 PM   #5
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Quote:
AFAIK, there is a separate module implementing regular expressions. I am not a Python guy, so I can't be more specific off the top of my head.
Have a look at the re module - it's part of the Python Standard Library.
 
  


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
LXer: Writing simple python setup commands LXer Syndicated Linux News 0 04-10-2009 01:41 AM
How do I make python programs run without entering the command python? trist007 Programming 5 03-22-2009 08:21 PM
automation of CLI commands using python bharatbsharma Programming 1 03-18-2008 02:13 AM
Python commands over ssh Kedelfor Programming 7 10-18-2005 04:07 AM
python, executing regular linux commands Robert0380 Programming 3 06-26-2003 03:35 PM

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

All times are GMT -5. The time now is 05:16 AM.

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