Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Best command for running shell command

Reply
Thread Tools

Best command for running shell command

 
 
Donald Duck
Guest
Posts: n/a
 
      07-11-2006
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.

 
Reply With Quote
 
 
 
 
Roy Smith
Guest
Posts: n/a
 
      07-11-2006
In article < E>,
Donald Duck <> wrote:

> 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.
 
Reply With Quote
 
 
 
 
Thomas Nelson
Guest
Posts: n/a
 
      07-11-2006
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 < E>,
> Donald Duck <> wrote:
>
> > 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.


 
Reply With Quote
 
iapain
Guest
Posts: n/a
 
      07-11-2006
> 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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
threads and timeout -> running a shell command / want to guard againstinfinite loops Marcus Liddle Python 2 02-11-2013 06:28 AM
python 2.x and running shell command tekion Python 3 12-24-2009 10:02 PM
Quit program that is running in command shell Java and Swing Java 4 09-11-2006 06:13 PM
running a shell command from a python program Sandman Python 4 02-23-2005 06:25 PM
can I run unix shell command in the ModelSim shell? clinton__bill@hotmail.com VHDL 2 02-18-2005 10:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57