473,287 Members | 3,228 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,287 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 1327
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: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.