use lines as argument to a command

S

Shoryuken

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.
 
A

Amit Khemka

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,
 
S

Shoryuken

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,

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")?
 
A

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")?

Since subprocess module allow you to call programs through (linux)
shell , you can use the same syntax in your command.

example:

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top