Greetings,
I have been trying to find a way to determine the return value (that
is: success/fail) of a spawned process (specifically scp).
Currently, I am using an Expect match, along with the values the match
returns to determine if the spawned command finished or failed.
For Example:
# Spawn our command
$cmd = Expect->spawn($scp);
$cmd->expect(60, -re => 'Enter passphrase| password:');
print $cmd "$password\r";
# Check for any returned info from scp command
@array = $cmd->expect(undef, -re => '\r\n.+');
$stuff = $cmd->exp_match();
$cmd->soft_close();
if ($array[1] eq '2:EOF') # Finished OK
{ ... }
else # Command Failed
{ print "We had an error: $stuff\n"; }
Is this a proper way to check the status of the spawned process? It
seems to work ok, but it also feels a little bit contrived.
Thank you in advance
Ryan Heatwole
|