Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Expect for Windows

Posted by mryge (mryge), 14 August 2004

I have a C# program (prompt.exe) and a Perl program
( Both programs simply prompts user name
and outputs (stdout) "Hello <username>".

The program run looks like this (for both programs):
> prompt.exe
> Name:
# user enter, say: Memomana.<return>
> Hello Memomana.

Running the Perl program with the Expect script below
is just fine.
# --- Expect script ---
package require Expect
spawn perl
expect "Name:"
send "Memomana"
expect eof

However, running the C# executable program with a
similar Expect script (below) causes the script to
hang until time out.
# --- Expect script ---
package require Expect
spawn prompt.exe
expect "Name:"
send "Memomana"
expect eof

# --- Output ---
> Name:
# The program will halt until timeout.

Can anybody help me to solve this mystery? Any help is

I use ActiveState Expect for Windows 1.0 (based on Expect 5.40).


Posted by admin (Graham Ellis), 14 August 2004
I would look at

a) Turn around delays
b) End of line characters


Does the "Name:" prompt also have a space after it?  If so, might be worth including it in the expect string.  Could be that your response is sent before the C# program is ready for it.  What about waiting for a few milliseconds after the prompt is received.  And so you need to add \r or \n onto the end of the send string?

Just some thoughts / areas for you to research.  Please do post a follow up if one of these solves it (or if it turns out to be something else!)

Posted by mryge (mryge), 14 August 2004
Yes, there is an extra space after "Name: ". However, it is fine (confirmed by running the Perl program with Expect).

The major problem with the C# program is that after running the Expect program:
> tclsh prompt.tcl

The command-line console hung--it even never showed "Name:" on the screen. Nonetheless, by looking at the Task Manager, there are actually 2 new processes created (one is for the Expect program and another is the spawned C# process).

When I run the Perl program with Expect, the output looks like:
--- output ---
Name: Hello Memomana.

That is, the Expect program sends "Memomana" right after it receives "Name: " and, then, the Perl program outputs (stdout) "Hello Memomana".

My guess is that the spawning of the C# process seems to be erroneous. Help?

Thank you.


Posted by admin (Graham Ellis), 14 August 2004
I'm wondeing if the C# program isn't using STDIN and/or STDOUT but is written to access keyboard and / or screen directly.  If you run it with redirects to / from file, does it work?

Another possibility ... it's possible for a program to check whether it's running with STDIN and STDOUT being interactive devices or not, and perform differently in each case. Is the C# program doing this? [[ Have a look at the -t operator in Perl, which is how Perl can determine this ... I don't know enough C# to know how it does it]].    Password changing programs, security scripts and the like can use this technique to avoid being run non-interactive, and I wonder if this is happening

Edit to add ... Some programs supress their prompting if the input is not interactive.   If your C# program feels its input is not interactive, it won't come up with the "Name: " prompt but will just wait for input. Sounds rather like what you've described is happening in your latest post??

Posted by mryge (mryge), 22 August 2004
It seems that 'Expect for Windows' can not "communicate" with the CLR-based C# program.

Using Expect in Cygwin (not 'Expect for Windows') will solve this frustation.

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho