如何检查 Expect->spawn($command) 是否成功?
我在 Expect->spawn($command)
中传递 scp 命令,我还基于 $object->expect()
传递密码或密码 + OTP代码>. 您能否告诉我是否有办法确定命令是否已成功运行?
我正在尝试 $object->after()
,但它给出的密码提示是之前的 $object->expect()
还探索了 $object->exitstatus()
,它将为空,因为对象未退出。
my $expect_obj = new Expect;
$expect_obj->log_stdout(0);
my $spawn = $expect_obj->spawn(split/\s+/, "scp $src $dest");
my $pos = $expect_obj->expect(60,
[qr/password.*: $/, sub {my $self = shift; $self->send("$pass\n")}],
);
如何判断命令是否成功?
I am passing an scp command in Expect->spawn($command)
, I am also passing the password or password + OTP based on a $object->expect()
.
Could you let me know if there is a way to determine if the command has been run successfully ?
I'm trying $object->after()
, but it's giving the password prompt which is the previous $object->expect()
also explored $object->exitstatus()
, it'll be empty since the object is not exited.
my $expect_obj = new Expect;
$expect_obj->log_stdout(0);
my $spawn = $expect_obj->spawn(split/\s+/, "scp $src $dest");
my $pos = $expect_obj->expect(60,
[qr/password.*: $/, sub {my $self = shift; $self->send("$pass\n")}],
);
How do I determine if the command is successful ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 waitpid ,如 这个答案。它将把子进程的退出代码分配给
$?
($CHILD_ERROR
),请参阅 perlvar。这是一个例子:You can use waitpid as shown in this answer. It will assign the exit code of the child to
$?
($CHILD_ERROR
), see more information in perlvar. Here is an example: