473,382 Members | 1,766 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,382 software developers and data experts.

calling programs from python

RR
Hello,

I am trying to call a program in python as I would call it in the command
line. For example I want to do the following from python: command > file.
Then read this file. How do I call "command > file" ? Much help
appreciated.

-RR
Jul 18 '05 #1
4 2223
On Mon, 01 Dec 2003 19:27:34 -0500, "RR" <er********@yahoo.com> wrote:
Hello,

I am trying to call a program in python as I would call it in the command
line. For example I want to do the following from python: command > file.
Then read this file. How do I call "command > file" ? Much help
appreciated.


Use os.system() For example, on Unix:
import os
os.system( 'command > file' ) and on Windows: os.system('start C:\Python23\python.exe')


-- Dave
Jul 18 '05 #2
David MacQuigg wrote:
On Mon, 01 Dec 2003 19:27:34 -0500, "RR" <er********@yahoo.com> wrote:

Hello,

I am trying to call a program in python as I would call it in the command
line. For example I want to do the following from python: command > file.
Then read this file. How do I call "command > file" ? Much help
appreciated.

Use os.system() For example, on Unix:
import os
os.system( 'command > file' )
and on Windows:
os.system('start C:\Python23\python.exe')

-- Dave

This will work too:

import os
os.popen('command > file')

Kris

Jul 18 '05 #3
On Tue, 02 Dec 2003 16:02:26 GMT, Kristofer Wouk
<kr*******@hotpop.com> wrote:
[...]
import os
os.popen('command > file')


This is a little confusing. Do you intend the output from 'command'
to go to 'file' or to the pipe you just opened?

If you are opening a pipe (to be read as a file object) I would
suggest something like this:
import os
file = os.popen('cat makefile | grep pyuic')
file.readlines() ['\tpyuic ModelSelector.ui > ModelSelector.py\n']

If you are just executing a command and not needing to process any
output from the command (other than its completion status), I would
stick with the more general:
import os
status = os.system('command > file')
status
0


--Dave

Jul 18 '05 #4
David MacQuigg <sh****@127.0.0.1> wrote in message news:<k0********************************@4ax.com>. ..
On Mon, 01 Dec 2003 19:27:34 -0500, "RR" <er********@yahoo.com> wrote:
Hello,

I am trying to call a program in python as I would call it in the command
line. For example I want to do the following from python: command > file.
Then read this file. How do I call "command > file" ? Much help
appreciated.


Use os.system() For example, on Unix:
import os
os.system( 'command > file' ) and on Windows: os.system('start C:\Python23\python.exe')


-- Dave


Windows Python os module has os.startfile()

os.startfile('C:\Python23\python.exe')

-- Richard
Jul 18 '05 #5

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

Similar topics

10
by: Kyler Laird | last post by:
I need to submit C/C++ code for a class. (It's not a programming class. The choice of language is inertial. I think that it mostly serves to distract students from the course subject.) I'm...
9
by: F. GEIGER | last post by:
I've dev'ed a Python prototype of an app, that besides the internals making it up has a gui. While test-driven dev'ing the app's internals in Python is fun as usual, dev'ing the GUI is not so...
2
by: calfdog | last post by:
Hello, Does anyone know a workaround for calling fireEvent. With the latest from Microsoft OS XP2 and Hot fixes to IE it now gives an "access denied" error in Python when called. Here is what...
6
by: Yevgeniy (Eugene) Medynskiy | last post by:
Hi all, This is probably a very newbie question, but after searching google and docs @ python.org I can't find an answer, so maybe someone would be able to help? I'd like to call command-line...
4
by: soumitra.mishra | last post by:
Hi All, I want to call (execute) some python scripts from my C# program. I know that this can be done but have not idea how. The other option that I can think of is developing python web...
35
by: Michel Sanner | last post by:
Hello, One of the greatest feature of Python in my opinion is the way the interpreter can be used to integrate a wide variety of software packages by dynamically linking them. This approach has...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
47
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both...
16
by: Jaco Naude | last post by:
Hi there, This is my first post over here and I hope someone can give me some guidance. I'm trying to embed Python into a Visual C++ 2008 application and I'm getting linker problems. I've...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.