473,508 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting from command line options to file

hi folks
I am new to python. I have a module does call a os.command(cmd) where
cmd is a rpm command.
Instead of using os.command and getting the results on command line ,
i would like to dump the output in a file. Is os.command(cmd >
filename) the most efficient command??
thanks

Apr 16 '07 #1
3 1549
CSUIDL PROGRAMMEr wrote:
hi folks
I am new to python. I have a module does call a os.command(cmd) where
cmd is a rpm command.
Instead of using os.command and getting the results on command line ,
i would like to dump the output in a file. Is os.command(cmd >
filename) the most efficient command??
I think the best thing to do would be something like this (Python 2.5):

from __future__ import with_statement
import subprocess

with file("test.out", "w") as outfile:
subprocess.check_call(["ls", "/etc"], stdout=outfile)
--
Michael Hoffman
Apr 16 '07 #2
On Apr 16, 1:08 pm, Michael Hoffman <cam.ac...@mh391.invalidwrote:
CSUIDL PROGRAMMEr wrote:
hi folks
I am new to python. I have a module does call a os.command(cmd) where
cmd is a rpm command.
Instead of using os.command and getting the results on command line ,
i would like to dump the output in a file. Is os.command(cmd >
filename) the most efficient command??

I think the best thing to do would be something like this (Python 2.5):

from __future__ import with_statement
import subprocess

with file("test.out", "w") as outfile:
subprocess.check_call(["ls", "/etc"], stdout=outfile)
--
Michael Hoffman

but what if i have python which is 2.4??
Apr 20 '07 #3
En Fri, 20 Apr 2007 17:48:10 -0300, CSUIDL PROGRAMMEr
<sy*********@yahoo.comescribió:
On Apr 16, 1:08 pm, Michael Hoffman <cam.ac...@mh391.invalidwrote:
>CSUIDL PROGRAMMEr wrote:
hi folks
I am new to python. I have a module does call a os.command(cmd) where
cmd is a rpm command.
Instead of using os.command and getting the results on command line ,
i would like to dump the output in a file. Is os.command(cmd >
filename) the most efficient command??

I think the best thing to do would be something like this (Python 2.5):

from __future__ import with_statement
import subprocess

with file("test.out", "w") as outfile:
subprocess.check_call(["ls", "/etc"], stdout=outfile)
--
Michael Hoffman


but what if i have python which is 2.4??
Omit the with statement:

import subprocess

outfile = open("test.out", "w")
try:
subprocess.check_call(["ls", "/etc"], stdout=outfile)
finally:
outfile.close()

--
Gabriel Genellina
Apr 20 '07 #4

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

Similar topics

2
2646
by: joe | last post by:
Hello, I have the following commands: testb -s <size> testb -s <size> -o <input file> testb -s <size> -o <codes> How do i split the commands so that all three are valid. And how do i check...
4
5968
by: Sean Shanny | last post by:
To all, Running into an out of memory error on our data warehouse server. This occurs only with our data from the 'September' section of a large fact table. The exact same query running over...
4
4969
by: Bit byte | last post by:
I have a project that I normally build (without problems) from the DevStudio IDE. However, I have embarked on automating all my builds (this test project being one of several). The project...
8
3492
by: Andrew Robert | last post by:
Hi Everyone. I tried the following to get input into optionparser from either a file or command line. The code below detects the passed file argument and prints the file contents but the...
3
10306
by: jlw16 | last post by:
Hello, I’m trying to use my vbs script to get a command line argument for a file which will need to be opened through QuickTestPro. Below are the commands I’m using: Dim qt_file 'As String ->...
4
23356
by: no_spam_for_gman | last post by:
Hi, I can turn off autocommit within the command window but I cannot figure out how to turn it off when you are in the IBM DB2 Command Line Processor. Does anybody knows how? By the way I mean...
6
6792
by: Armel Asselin | last post by:
Hello, I'm searching for a simple command line tool to manipulate XML files. The idea would be commands such as that: xmanip-tool set /document/xpath/@name="value" remove //wrong-nodes add...
2
1808
by: Lucas Malor | last post by:
Hello all. I'm trying to do a little script. Simply I want to make a list of all options with them default values. If the option is not specified in the command line, the script must try to read it...
51
4083
by: Ojas | last post by:
Hi!, I just out of curiosity want to know how top detect the client side application under which the script is getting run. I mean to ask the how to know whether the script is running under...
0
7135
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...
1
7067
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
7505
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
5650
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,...
1
5060
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...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.