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
 
This week, we're updating our course layouts and descriptions. Presentation and materials always gently change over time, but just occasionally there's a need to make a step change to clear out some of the old and roll in the new. That's now happening - but over a long and complex site it's not instant and you'll see sections of the site changing up to and including 19th September.

See also [here] for status update
 
Expect for Windows

Posted by mryge (mryge), 14 August 2004
Hi,

I have a C# program (prompt.exe) and a Perl program
(prompt.pl). 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 prompt.pl
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
appreciated.

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


Memomana

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

a) Turn around delays
b) End of line characters

first.

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.


Memomana

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 www.opentalk.org.uk 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., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho