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

Control an external console program

Hi,

I know Python since about 3 days or so and I like it very much :-) I am
currently tying to control an external console driven program but I
have encountered some problems while trying to do so.

Suppose I will try to control a program like a ftp command line client.
At first I wrote something like:

import popen2

fin, fout = popen2.popen2("ftp")
print "Out: " + fin.readline()

I expected to get an output like "Out: ftp>" but I got not nothing. I
think the reason is that readline() reads a line till it encountered a
"\n" or EOF, but nothing of both happen because the ftp client just
wrote the prompt and is now waiting for input, or not? Therefore I
thought, ok I just write an "\n" to fout and because the ftp client
will echo it I can read a line with readline() and get the prompt. But
it doesn't work either. Now I started asking myself if it just work
this way at all. Instead of just writing a "\n" to fout I wrote
"help\n" and read a line from fin and this time I got the first line of
the output from the help command *yeeha* :-) Unfortunately any
successive read from fin does not work. I can only read the first line
the help command issued, not the 5 or 6 following the first line.

So my question is how do I control a command line tool? I want to
interactively control a command line tool, so I will issue some
commands need the output from the tool and act acording to it. I guess
readline() is not the answer because if there is no line to read
present it just waits. Can anyone give me some hints for writing such a
program? How is the python command line tool integrated in the many
IDE's around? I guess they have the same problem, or not?

Bye
Alex

Jul 18 '05 #1
1 2206
Alexander Stante <al*********@yahoo.de> wrote:
So my question is how do I control a command line tool? I want to


Check out http://pexpect.sourceforge.net/

martin
Jul 18 '05 #2

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

Similar topics

1
by: Will Stuyvesant | last post by:
I never used the popen or popen2 libraries but it is my understanding that they can capture the output of console based programs. Is it also possible to send keystrokes to console base programs? ...
4
by: Matthew Maylin | last post by:
I'm trying to call a external program from another. My main program is a GUI buildin borland c++ builder, and my sibbling is compiled Matlab code. I would like to call to the program, passing...
3
by: Daniel | last post by:
Hi, Does anyone know if it is possible to interact with another console based program. For example, relaying data back and forth between the user and the program. ie. 1. User interacts with...
9
by: Alvin Bruney [MVP] | last post by:
Exceptions must not be used to control program flow. I intend to show that this statement is flawed. In some instances, exceptions may be used to control program flow in ways that can lead to...
6
by: Dmitry Duginov | last post by:
My web application uses resource files to keep localized strings etc. Those resource files prepared by external console program, which extracts this stuff from the database. Is there a way to...
3
by: lotus | last post by:
Hi all. I want to control two different instrtument but have simliar functionality. Acually the fisrt one is controlled by using serial communication, and the other is controlled by LAN...
2
by: Lonifasiko | last post by:
Hi group, I must launch from my Winforms application another application (.exe developed by the client) which response time sometimes can be more or less 30 seconds. I'm using ProcessManager...
24
by: tizi_de | last post by:
Hello all, I'm looking for a sample program in C to print out lines not to the standard MS Dos Box but into a different control e.g. text control. Has C the possibility to do printouts to a...
1
by: =?Utf-8?B?Q3JhaWc=?= | last post by:
Hi Guys, I am trying to caputre the output for an external application. The idea is to use the System.Diagnostics.Process to run the exe in a process and redirect the output to a string. When...
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: 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
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...
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
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...
0
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...

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.