473,396 Members | 1,768 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.

use lines as argument to a command

I'm new to Python, so my question may sounds naive. Here is it.

I have a text file like this:

www.a.com
www.b.com
www.c.com
....

I want to read one line from this file at a time, which I know how to
do. And use it as an argument to a command, for example, telnet www.a.com
and so on. However I have no idea how to do this task.

My purpose is to generate a brief report.

Thank you in advance.

Oct 15 '07 #1
3 1331
On 10/15/07, Shoryuken <sa***************@gmail.comwrote:
I'm new to Python, so my question may sounds naive. Here is it.

I have a text file like this:

www.a.com
www.b.com
www.c.com
...

I want to read one line from this file at a time, which I know how to
do. And use it as an argument to a command, for example, telnet www.a.com
and so on. However I have no idea how to do this task.
I guess that you want to loop over a file and for each line in the
file you want to call some
external program with the line as the argument.

Have a look at subprocess module
http://docs.python.org/lib/module-subprocess.html

If there is some else that you meant, please specify .

Cheers,

--
--
Amit Khemka
Oct 15 '07 #2
I guess that you want to loop over a file and for each line in the
file you want to call some
external program with the line as the argument.

Have a look at subprocess module
http://docs.python.org/lib/module-subprocess.html

If there is some else that you meant, please specify .

Cheers,

--
--
Amit Khemka
Thanks alot, its working now. But I have another question (sorry I'm
so noob), how can I redirect a command's output to a file (just like
executing a linux command "dmesg>>stat.txt")?
Oct 16 '07 #3
On 10/16/07, Shoryuken <sa***************@gmail.comwrote:
I guess that you want to loop over a file and for each line in the
file you want to call some
external program with the line as the argument.

Have a look at subprocess module
http://docs.python.org/lib/module-subprocess.html

If there is some else that you meant, please specify .
Thanks alot, its working now. But I have another question (sorry I'm
so noob), how can I redirect a command's output to a file (just like
executing a linux command "dmesg>>stat.txt")?
Since subprocess module allow you to call programs through (linux)
shell , you can use the same syntax in your command.

example:
>>from subprocess import call
call("echo foo >bar.txt", shell=True)
Cheers,

--
--
Amit Khemka
Oct 16 '07 #4

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

Similar topics

24
by: Nalla | last post by:
Hi, I want a program. It should be a command line one. you can input the path of a folder(preferably) or a file...it should count the no. of lines between the compiler directives, ifdef win32 and...
1
by: DanielB | last post by:
Does anyone know what the command line argumentto launch a screensaver's options/configuration dialog is on Windows XP Pro? From most of the example source code I can find on the web, it would...
1
by: Vagabond Software | last post by:
I am launching the EXTRACT.EXE command from my application using the Process class. Everything seems to be working fine except the path I use as the destination argument for the EXTRACT command...
16
by: Highlander | last post by:
Hello all. I'm a systems admin and not a developer. I work in a large IT department with teams of developers. Currently we are asking them to develop a utility for us that will migrate code, among...
3
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 ->...
6
by: virgincita schmidtmann | last post by:
Good evening, I would like to pass the size of an array from the commandline. int main(int argc, int *argv) { .... max=*argv; int list; ....
8
by: A. Anderson | last post by:
Howdy everyone, I'm experiencing a problem with a program that I'm developing. Take a look at this stack report from GDB - #0 0xb7d782a3 in strlen () from /lib/tls/i686/cmov/libc.so.6 #1 ...
19
by: Pavan | last post by:
Hi, I want to know if there is any software for measuring lines of code of my c++ application. I found out a tool, sloccount, but it gives only physical lines of code. I found out one more...
6
by: =?Utf-8?B?Rm9ycmVzdCBIZWxsZXI=?= | last post by:
The only code that is helpful is this: fp = New IO.StreamReader(filename, New System.Text.UnicodeEncoding(True, False), False) If I pass a command line argument to my program that is not from...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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
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...

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.