473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Python and Unix Commands

Hi,

I have a question relating to how Unix commands can be issued from
Python programs. Im am currently writing a large test script in python
and I need this script to call three other separate Python scripts,
where each one executes in it own thread of control. I would like to
use a Unix command to get each script to run in its own shell. I have
tried using the "Commands" module but after I issue the
first "command", execution blocks until I kill the called script. Is
there a way around this??

Thanks for your time,
I would really appreciate any assistance,

Tim.

Sep 19 '05 #1
2 2981
> I have a question relating to how Unix commands can be issued
from
Python programs.
There are numerous methods including the commands module that
you have already discovered, the os.system() call and the
various os.popen/os.execXX calls.

Also Python 2.4 has introduced the subprocess module that
superceded most of these.
and I need this script to call three other separate Python
scripts,
where each one executes in it own thread of control.
Do you actually need to execute the python scripts as scripts,
each with its own instance of the intrerpreter? (For testing
the answer may well be yes) Or would it be possible to simply
execute the script code as a function from within a thread of
your main program?

commands/os.system/subprocess etc are usually used to launch
Unix commands or other executable files, not other Python
scripts. It's easier to interact with Python from within
Python...
use a Unix command to get each script to run in its own shell.
I have
tried using the "Commands" module but after I issue the
first "command", execution blocks until I kill the called
script. Is
there a way around this??


If you must do this then I'd suggest you need to launch a
separate
thread per shell then use commands/subprocess to launch each
interpreter/script invocation from within its own thread.

[ If you are not interested in the results you could just use
the Unix '&' character to execute the processes in the
background ]

HTH,
--
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
Sep 19 '05 #2
>>>>> "timdoyle05" <ti********@yahoo.com> (T) wrote:
T> Hi,
T> I have a question relating to how Unix commands can be issued from
T> Python programs. Im am currently writing a large test script in python
T> and I need this script to call three other separate Python scripts,
T> where each one executes in it own thread of control. I would like to
T> use a Unix command to get each script to run in its own shell. I have
T> tried using the "Commands" module but after I issue the
T> first "command", execution blocks until I kill the called script. Is
T> there a way around this??


Use the subprocess module. If you have an older python, you could use
os.system(command + "&") or install the subprocess module yourself.
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
Sep 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
4
by: Logan | last post by:
Several people asked me for the following HOWTO, so I decided to post it here (though it is still very 'alpha' and might contain many (?) mistakes; didn't test what I wrote, but wrote it - more or...
52
by: Olivier Scalbert | last post by:
Hello , What is the python way of doing this : perl -pi -e 's/string1/string2/' file ? Thanks Olivier
3
by: Kory Wheatley | last post by:
Hi all, I've just started to learn Python and I have a question. What is the syntax to embed Unix commands, or call other programs within a Python script? for example I would like to use a...
10
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. ...
1
by: sub1ime_uk | last post by:
I apologise if this is a well known problem. I've searched and can't find a clear description or fix. Hope someone can help. I am running my Python scripts under Windows 2000 using Python 2.4...
2
by: Xah Lee | last post by:
Python Doc Problem Example: os.system Xah Lee, 2005-09 today i'm trying to use Python to call shell commands. e.g. in Perl something like output=qx(ls) in Python i quickly located the...
7
by: Bin Chen | last post by:
Hi, I want to do following: get a user input regex, then pass this as a parameter to grep, and then get the result from grep. Any code snip to implement the similar function? I am a python...
2
by: sixtyfootersdude | last post by:
Hey all! Just doing some tinkering with python. I am running mac os x and I am wondering how I can call unix commands from python. In C I think I would use a fork, although it has been...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.