LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   expect says it cant send the string to the spawned command (https://www.linuxquestions.org/questions/programming-9/expect-says-it-cant-send-the-string-to-the-spawned-command-697919/)

exceed1 01-17-2009 06:51 AM

expect says it cant send the string to the spawned command
 
Hi

I've created a perl script that is using the Expect.pm module which lets me work with Expect in Perl.

The code is shown below (and the problems with the code are written in the comments):
Code:

#!/usr/bin/perl

# loading the expect module
use Expect;
use warnings ;

# creating a new expect object
my($exp) = new Expect;

# set Expect options
$exp-> raw_pty(1); #eliminates echo back to expect
$exp-> log_file("/expect.log", "w"); # log to expect.log
$exp-> debug(1); # debug level 1

# spawn the expect command
$exp-> spawn("ssh -l exceed localhost uname -o") ;

# check for the string "exceed@localhost's password:" string or print an error message
# the text is here found (i tested with an if-test and by replacing the text to search
# for so it would print the error message which it did
$exp->expect(5,"exceed\@localhost's password:") or die "didnt find password prompt" ;

# so, the text is found, but for some reason it doesnt send the string. here it prints out
# the error message "could not send string
$exp->send("password") or die "could not send string" ;

As written in the comments, the error message "could not send strnig" is written out to the screen. I have tried all the debugging levels available in the debug function, but i cant see why its not working, below are the output when running the code with debug level 1 for the debug function:
Code:

Spawned 'ssh -l exceed localhost uname -o'
        spawn id(3)
        Pid: 4374
        Tty: /dev/pts/3
 at /usr/local/share/perl/5.10.0/Expect.pm line 181
        Expect::spawn('Expect=GLOB(0xa006ae8)', 'ssh -l exceed localhost uname -o') called at expect3.pl line 16
Starting EXPECT pattern matching...
 at /usr/local/share/perl/5.10.0/Expect.pm line 561
        Expect::expect('Expect=GLOB(0xa006ae8)', 5, 'exceed@localhost\'s password:') called at expect3.pl line 22
exceed@localhost's password: could not send string at expect3.pl line 26.
Closing spawn id(3).
 at /usr/local/share/perl/5.10.0/Expect.pm line 1431
        Expect::hard_close('Expect=GLOB(0xa006ae8)') called at /usr/local/share/perl/5.10.0/Expect.pm line 1621
        Expect::DESTROY('Expect=GLOB(0xa006ae8)') called at expect3.pl line 26
        eval {...} called at expect3.pl line 26
spawn id(3) closed.
Pid 4374 of spawn id(3) terminated, Status: 0x01

I also ran an strace on the process and i got the following output:
Code:

Process 4374 attached - interrupt to quit
read(4, "t"..., 1)                      = 1
read(4, "i"..., 1)                      = 1
read(4, "g"..., 1)                      = 1
read(4, "e"..., 1)                      = 1
read(4, "r"..., 1)                      = 1
read(4, "1"..., 1)                      = 1
read(4, "2"..., 1)                      = 1
read(4, "3"..., 1)                      = 1
read(4, ""..., 1)                      = 0
--- SIGHUP (Hangup) @ 0 (0) ---
--- SIGCONT (Continued) @ 0 (0) ---
sigreturn()                            = ? (mask now [])
write(4, "\n"..., 1)                    = -1 EIO (Input/output error)
rt_sigaction(SIGALRM, {SIG_DFL}, NULL, 8) = 0
rt_sigaction(SIGHUP, {SIG_DFL}, NULL, 8) = 0
rt_sigaction(SIGINT, {SIG_DFL}, NULL, 8) = 0
rt_sigaction(SIGQUIT, {SIG_DFL}, NULL, 8) = 0
rt_sigaction(SIGPIPE, {SIG_IGN}, NULL, 8) = 0
rt_sigaction(SIGTERM, {SIG_DFL}, NULL, 8) = 0
rt_sigaction(SIGTSTP, {SIG_DFL}, NULL, 8) = 0
rt_sigaction(SIGTTIN, {SIG_DFL}, NULL, 8) = 0
close(4)                                = 0
kill(4374, SIGHUP)                      = 0
--- SIGHUP (Hangup) @ 0 (0) ---
Process 4374 detached

When i run "ssh -l exceed localhost uname -o" from the command-line it works without any problems, so i dont know what that I/O error is all about.

Is there anyone that can see any errors with the code ? Its not sending the string to the spawned command. Thanks for any help, it appriciated.


All times are GMT -5. The time now is 08:48 PM.