473,396 Members | 2,115 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,396 software developers and data experts.

system call in python

Hi,

A question about how to execute a system command from python program. e.g.
in a python script, I need to run another program written in C++, and after
that come back to the same python program.

Is it the system module, and which function do I use to do this?

Thanks a lot
Catherine
Jul 18 '05 #1
5 125697
Catherine Yang wrote:
Hi,

A question about how to execute a system command from python program. e.g.
in a python script, I need to run another program written in C++, and after
that come back to the same python program.

Is it the system module, and which function do I use to do this?

Thanks a lot
Catherine

Probably you are looking for os.system, as in:

import os
cmd = 'ls -l /usr/bin'
os.system(cmd)

Note that this will not capture the output of the system command; you
can use the os.popen family of commands to do that.

-- Graham
Jul 18 '05 #2
Hi,

I think you can do the following:

import commands
commands.getstatusoutput("...your command to execture program...")

SATISH
On Thursday 14 August 2003 01:37 am, Graham Fawcett wrote:
Catherine Yang wrote:
Hi,

A question about how to execute a system command from python program. e.g.
in a python script, I need to run another program written in C++, and
after that come back to the same python program.

Is it the system module, and which function do I use to do this?

Thanks a lot
Catherine


Probably you are looking for os.system, as in:

import os
cmd = 'ls -l /usr/bin'
os.system(cmd)

Note that this will not capture the output of the system command; you
can use the os.popen family of commands to do that.

-- Graham


--
SATISH K.CHIMAKURTHI
GRAD. RESEARCH ASSISTANT
UNIVERSITY OF KENTUCKY
LEXINGTON
KENTUCKY STATE
Jul 18 '05 #3


Catherine Yang wrote:
Hi,

A question about how to execute a system command from python program. e.g.
in a python script, I need to run another program written in C++, and after
that come back to the same python program.

Is it the system module, and which function do I use to do this?


You can use the os.system() to execute a program accessible from your
path or specified explicitly:
import os
os.system('ls')


For more info on process control, take a look at:

http://www.python.org/doc/current/lib/os-process.html

Jul 18 '05 #4
Catherine Yang wrote:
Wow, you guys are *really fast and very helpful*. Thanks !!!!!!!

We're merely trying to emulate our favourite language. ;-)

-- Graham

Jul 18 '05 #5
Graham Fawcett <fa*****@teksavvy.com> writes:
On an editorial aside, I'd nominate the "commands" module as a Python
wart.
I seem to recall python-dev agrees with you...
It's not that the functions in this module aren't useful, but why
are they divorced from the very-much-related commands in the "os"
module?

IIWG (If I were Guido) I think I would at least sub-package this
module as os.commands (in the spirit of os.path). While I was at it,
I'd probably do the same for shutil (--> os.shutil).
Hmm. In a way, os is already too fat, I'm not sure *more* stuff
should end up in there. If it was a real package, then maybe
os.commands, os.net, os.shutil would make sense, but it's not.

Occasionally people suggest that you should get at the standard
library by doing something like

from org.python import socket

but then Guido shoots them :-)
The Python standard library is full of dark corners bearing wondrous
mysteries, a Library of Alexandria full of useful code... but surely
even Alexandria's librarians put similar scrolls on the same shelf!


This is what Alex Martelli is for :-)

Cheers,
mwh

--
If I didn't have my part-time performance art income to help pay
the bills, I could never afford to support my programming
lifestyle. -- Jeff Bauer, 21 Apr 2000
Jul 18 '05 #6

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

Similar topics

4
by: paritosh mahana | last post by:
Hi all, How can I call python code from my C# code. One thing is to make an ..exe file of the python program and then try to call it from my C# code. But I don't like that idea. Is there any...
7
by: rahul8143 | last post by:
hello, what is difference between system call and library function call? Does library function call can have context switch to kernel mode? regards, rahul
0
by: haynes george | last post by:
hi .. I was reading the tutorial "Extending and Embedding the python interpreter" available with python .. http://www.python.org/doc/2.2.3/ext/ext.html As per given in the tutorial i...
8
by: redefined.horizons | last post by:
I did some searching for this topic, but couldn't find anything. A search of this list only turned up an old post from 2002. I'd like to add a comprehesive help system to my Python Application....
7
by: Marco | last post by:
Hello,every one, I meet a question: in my old script, I usually use os.popen2() to get info from standard unix(LinuX) program like ps,ifconfig... Now, I write a OO-based programme, I still use...
6
by: leoman730 | last post by:
This is one of the interview question this morning, hope someone can help out with this. Thanks. What is the different between System call and library call?
3
by: Allen | last post by:
I use try catch, but cannot catch the execeptions of execution python method. PYCALL_API void PyCall(const char * pszModule, const char * pszFunc, void * pArg) { if (pszModule == NULL ||...
1
by: Calder Coalson | last post by:
I was searching for ways to get the return value from os.system() calls, when I came across this from 6 years ago. I tried what was suggested in this thread, but output =...
1
by: earthdirt | last post by:
I'm a newbie and I'm in way over my head with a pressing real world problem I need to solve with python.....one that isn't waiting for me to learn all I need to learn about programming. I have 3...
0
ashitpro
by: ashitpro | last post by:
Writing System Call Wrappers in User Space. Recently I saw a post in Linux/Unix section to know the user who deleted the file in linux. Currently there is nothing in linux which could achieve...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.