Help with Perl Expect.

F

Franklin Lee

Hi all,

Now I met problem when using Perl Expect.
I want to get the return code for cmd.
For example,
df -k
echo $?

codes as below
****************************************
....
exp->send("echo \$?\r");
exp->expect($timeout, "echo \$?\r\n");
exp->expect($timeout, "([0-9]+)\r\n");

.....
****************************************

But I can't use ([0-9]+ to match 0 or other number?

So could you tell me the reason? or how should I do?

Thank you!

Franklin
 
C

Charles DeRykus

Hi all,

Now I met problem when using Perl Expect.
I want to get the return code for cmd.
For example,
df -k
echo $?

codes as below
****************************************
...
exp->send("echo \$?\r");
exp->expect($timeout, "echo \$?\r\n");
exp->expect($timeout, "([0-9]+)\r\n");

....
****************************************

But I can't use ([0-9]+ to match 0 or other number?

So could you tell me the reason? or how should I do?

Would Net::Telnet be an alternative...

use Net::Telnet;
my $t = new Net::Telnet (...
$t->open(...
$t->login('acct', 'password');
my @output = $t->cmd('df -k;echo \$?=$?');
....

hth,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top