| |||||||||||
asking for expect which used to interact program? Posted by lanjun (lanjun), 2 November 2006 hi,I want to use a script file to control a c program. The file is flowing: test.exp file: #!/usr/bin/expect set timeout 1 log_file "test.txt" spawn test #send "123\r" #the paragram which needed by test program is stored in test1.txt file. set output [open test1.txt r] set f [read $output] send $f close $output #send "75,63,98\r" expect eof test.c file: #include <stdio.h> main() { int a,b,c,d; do { printf ("input a :\n"); scanf ("%d",&a); printf ("%d\n",a); }while (123!=a); printf ("Please input b,c,d:\n"); scanf ("%d,%d,%d", &b,&c,&d); printf("%d,%d,%d\n",b,c,d); } text1.txt file: 123 78,50,96 ok,lets run it.and get the result: spawn test 123 78,50,96input a: 123 Please input b,c,d: As you know, i expect to get this result: input a: 123 Please input b,c,d: 78,50,96 why??why i can't get the right result i expectedit makes me felt very wondering. can you give me some wonderfull advice for that. thank you very much!!!! Posted by admin (Graham Ellis), 2 November 2006 When you input the value to the C program, it echos back the input you made and you need to suck that up with your expect program.Posted by lanjun (lanjun), 3 November 2006 thanks for your kindness to reply my stupid question. "suck that up with your expect program", i'm sorry i cann't understand it very clearly. do you mean i must write something to get the c program's return value? en, let me see...is it possible? beacuse i cann't find one exppect command for that function. and do you have a good idea? Posted by admin (Graham Ellis), 3 November 2006 Your expect must also read back your inputs which are echoed by the server. In addition, you may like to clean up your display by setting log_user to 0. Posted by lanjun (lanjun), 3 November 2006 well, yeah, you are right. send inputs must be twice. so i get the right return value... ; expect language is so wondderful. i hope i can control it one day...hehe,that heared a little long..thanks,Graham Ellis!!! 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.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |