473,245 Members | 1,625 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,245 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 125686
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.