LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-17-2009, 07:51 AM   #1
exceed1
Member
 
Registered: Mar 2008
Location: oslo
Distribution: debian,redhat
Posts: 199

Rep: Reputation: 31
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.

Last edited by exceed1; 01-17-2009 at 08:12 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 10:06 PM
How to send get index string command to HID on linux? JerryMega Linux - Software 4 11-26-2008 11:15 PM
How to send get index string command to HID on linux? JerryMega Linux - Hardware 1 11-19-2008 05:17 AM
vpnc spawned from "expect" killed upon exit saravkrish Linux - General 1 01-29-2007 09:17 PM
CGI script problem: Send/Expect command echo on webpage rajatgarg Programming 2 07-11-2004 05:38 PM


All times are GMT -5. The time now is 08:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration