By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,836 Members | 2,059 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,836 IT Pros & Developers. It's quick & easy.

Best command for running shell command

P: n/a
I'm a little bit confused about what is the best way to run a shell command,
if I want to run a command like

xxxxxx -a -b yyyyyy

where I'm not interested in the output, I only want to make sure that the
command was executed OK. How should I invoke this (in a Unix/linux
environment)?

The command module seem to give the resulting output and the various popen
commands seem to be similar.

Jul 11 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <00*****************************@News.Individual.D E>,
Donald Duck <bl******@mac.comwrote:
I'm a little bit confused about what is the best way to run a shell command,
if I want to run a command like

xxxxxx -a -b yyyyyy

where I'm not interested in the output, I only want to make sure that the
command was executed OK. How should I invoke this (in a Unix/linux
environment)?
The most straight-forward way would be:

import os
status = os.system ("xxxxxx -a -b yyyyyy")
if status == 0:
print "it worked"
else:
print "it failed"

You might also want to look at the new (in 2.4) subprocess module.
Jul 11 '06 #2

P: n/a
Yes, I highly recommend the subprocess module. subprocess.call() can
do almost anything you want to do, and the options are all pretty
intuitive Whenever I need to write quick scripts for myself, it's what
I use.

THN
Roy Smith wrote:
In article <00*****************************@News.Individual.D E>,
Donald Duck <bl******@mac.comwrote:
I'm a little bit confused about what is the best way to run a shell command,
if I want to run a command like

xxxxxx -a -b yyyyyy

where I'm not interested in the output, I only want to make sure that the
command was executed OK. How should I invoke this (in a Unix/linux
environment)?

The most straight-forward way would be:

import os
status = os.system ("xxxxxx -a -b yyyyyy")
if status == 0:
print "it worked"
else:
print "it failed"

You might also want to look at the new (in 2.4) subprocess module.
Jul 11 '06 #3

P: n/a
where I'm not interested in the output, I only want to make sure that the
command was executed OK. How should I invoke this (in a Unix/linux
environment)?
Remember few things about executing program within python
1. Create a subprocess or child process and execute it.
2. You should use "Timeout stratagy" i.e your execution took more than
provided time then timeout this process. In linux/unix you may use
singnal alarm to implement it.

Best!

Jul 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.