Waiting on expect - until spawned program completes
up vote
1
down vote
favorite
I'm trying to use expect to spawn a program in an automation script in perl.
And I'm trying to decide how to wait on expect for this program to finish, since
- I can't rely on any string matching as the program is not consistent with how it exits
- I would like to wait on expect until the user prompt is seen and the user gets control.
Is there any means of doing it without performing a regex on the user prompt ? Any flags or exit codes I can rely on which tells the user has control now.
Thanks
regex perl unix expect exit
add a comment |
up vote
1
down vote
favorite
I'm trying to use expect to spawn a program in an automation script in perl.
And I'm trying to decide how to wait on expect for this program to finish, since
- I can't rely on any string matching as the program is not consistent with how it exits
- I would like to wait on expect until the user prompt is seen and the user gets control.
Is there any means of doing it without performing a regex on the user prompt ? Any flags or exit codes I can rely on which tells the user has control now.
Thanks
regex perl unix expect exit
Can you clarify your first sentence? Are you using perl's expect, or the plain Tcl expect and the spawned program is implemented in perl? Do you actually require expect for this task?
– glenn jackman
22 hours ago
Yes I'm using perl's expect. And the spawned program/task is basically a git clone of a remote repository. Now I'm unable to precisely tell when the cloning process is done and if I can proceed with the rest of my automation script
– seek
21 hours ago
1
If there is no interaction why useExpect
? How is the program "inconsistent" -- what are other ways for it to finish, other than just exit?
– zdim
19 hours ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm trying to use expect to spawn a program in an automation script in perl.
And I'm trying to decide how to wait on expect for this program to finish, since
- I can't rely on any string matching as the program is not consistent with how it exits
- I would like to wait on expect until the user prompt is seen and the user gets control.
Is there any means of doing it without performing a regex on the user prompt ? Any flags or exit codes I can rely on which tells the user has control now.
Thanks
regex perl unix expect exit
I'm trying to use expect to spawn a program in an automation script in perl.
And I'm trying to decide how to wait on expect for this program to finish, since
- I can't rely on any string matching as the program is not consistent with how it exits
- I would like to wait on expect until the user prompt is seen and the user gets control.
Is there any means of doing it without performing a regex on the user prompt ? Any flags or exit codes I can rely on which tells the user has control now.
Thanks
regex perl unix expect exit
regex perl unix expect exit
edited 21 hours ago
asked yesterday
seek
61
61
Can you clarify your first sentence? Are you using perl's expect, or the plain Tcl expect and the spawned program is implemented in perl? Do you actually require expect for this task?
– glenn jackman
22 hours ago
Yes I'm using perl's expect. And the spawned program/task is basically a git clone of a remote repository. Now I'm unable to precisely tell when the cloning process is done and if I can proceed with the rest of my automation script
– seek
21 hours ago
1
If there is no interaction why useExpect
? How is the program "inconsistent" -- what are other ways for it to finish, other than just exit?
– zdim
19 hours ago
add a comment |
Can you clarify your first sentence? Are you using perl's expect, or the plain Tcl expect and the spawned program is implemented in perl? Do you actually require expect for this task?
– glenn jackman
22 hours ago
Yes I'm using perl's expect. And the spawned program/task is basically a git clone of a remote repository. Now I'm unable to precisely tell when the cloning process is done and if I can proceed with the rest of my automation script
– seek
21 hours ago
1
If there is no interaction why useExpect
? How is the program "inconsistent" -- what are other ways for it to finish, other than just exit?
– zdim
19 hours ago
Can you clarify your first sentence? Are you using perl's expect, or the plain Tcl expect and the spawned program is implemented in perl? Do you actually require expect for this task?
– glenn jackman
22 hours ago
Can you clarify your first sentence? Are you using perl's expect, or the plain Tcl expect and the spawned program is implemented in perl? Do you actually require expect for this task?
– glenn jackman
22 hours ago
Yes I'm using perl's expect. And the spawned program/task is basically a git clone of a remote repository. Now I'm unable to precisely tell when the cloning process is done and if I can proceed with the rest of my automation script
– seek
21 hours ago
Yes I'm using perl's expect. And the spawned program/task is basically a git clone of a remote repository. Now I'm unable to precisely tell when the cloning process is done and if I can proceed with the rest of my automation script
– seek
21 hours ago
1
1
If there is no interaction why use
Expect
? How is the program "inconsistent" -- what are other ways for it to finish, other than just exit?– zdim
19 hours ago
If there is no interaction why use
Expect
? How is the program "inconsistent" -- what are other ways for it to finish, other than just exit?– zdim
19 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
It is not stated what else Expect
is used for, or how else the program may indicate its exit.
Assuming that at one point interaction stops and we only wait for the program to exit, you can use expect(undef)
use warnings;
use strict;
use feature 'say';
use Expect;
my $cmd = 'ls -l ./ | head -5; sleep 3';
my $exp = Expect->spawn( $cmd );
say "Started process ", $exp->pid;
$exp->raw_pty(1);
$exp->log_stdout(0);
# ...
$exp->expect(undef);
say "Program exited with status ", $exp->exitstatus;
say $exp->before;
If no output is expected after the program goes incommunicado remove before
.
Another way is to set up a $SIGCHLD
signal handler, where you check for the program's PID and set a flag that other code can then check. The PID is in a variable which need be declared before the handler and then set with pid
method after the process is started, so that it is legal (under strict
) to use in the handler and it is set for when the handler runs.
Then exitstatus
isn't useful (-1
) as the process is reaped in the handler.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
It is not stated what else Expect
is used for, or how else the program may indicate its exit.
Assuming that at one point interaction stops and we only wait for the program to exit, you can use expect(undef)
use warnings;
use strict;
use feature 'say';
use Expect;
my $cmd = 'ls -l ./ | head -5; sleep 3';
my $exp = Expect->spawn( $cmd );
say "Started process ", $exp->pid;
$exp->raw_pty(1);
$exp->log_stdout(0);
# ...
$exp->expect(undef);
say "Program exited with status ", $exp->exitstatus;
say $exp->before;
If no output is expected after the program goes incommunicado remove before
.
Another way is to set up a $SIGCHLD
signal handler, where you check for the program's PID and set a flag that other code can then check. The PID is in a variable which need be declared before the handler and then set with pid
method after the process is started, so that it is legal (under strict
) to use in the handler and it is set for when the handler runs.
Then exitstatus
isn't useful (-1
) as the process is reaped in the handler.
add a comment |
up vote
2
down vote
It is not stated what else Expect
is used for, or how else the program may indicate its exit.
Assuming that at one point interaction stops and we only wait for the program to exit, you can use expect(undef)
use warnings;
use strict;
use feature 'say';
use Expect;
my $cmd = 'ls -l ./ | head -5; sleep 3';
my $exp = Expect->spawn( $cmd );
say "Started process ", $exp->pid;
$exp->raw_pty(1);
$exp->log_stdout(0);
# ...
$exp->expect(undef);
say "Program exited with status ", $exp->exitstatus;
say $exp->before;
If no output is expected after the program goes incommunicado remove before
.
Another way is to set up a $SIGCHLD
signal handler, where you check for the program's PID and set a flag that other code can then check. The PID is in a variable which need be declared before the handler and then set with pid
method after the process is started, so that it is legal (under strict
) to use in the handler and it is set for when the handler runs.
Then exitstatus
isn't useful (-1
) as the process is reaped in the handler.
add a comment |
up vote
2
down vote
up vote
2
down vote
It is not stated what else Expect
is used for, or how else the program may indicate its exit.
Assuming that at one point interaction stops and we only wait for the program to exit, you can use expect(undef)
use warnings;
use strict;
use feature 'say';
use Expect;
my $cmd = 'ls -l ./ | head -5; sleep 3';
my $exp = Expect->spawn( $cmd );
say "Started process ", $exp->pid;
$exp->raw_pty(1);
$exp->log_stdout(0);
# ...
$exp->expect(undef);
say "Program exited with status ", $exp->exitstatus;
say $exp->before;
If no output is expected after the program goes incommunicado remove before
.
Another way is to set up a $SIGCHLD
signal handler, where you check for the program's PID and set a flag that other code can then check. The PID is in a variable which need be declared before the handler and then set with pid
method after the process is started, so that it is legal (under strict
) to use in the handler and it is set for when the handler runs.
Then exitstatus
isn't useful (-1
) as the process is reaped in the handler.
It is not stated what else Expect
is used for, or how else the program may indicate its exit.
Assuming that at one point interaction stops and we only wait for the program to exit, you can use expect(undef)
use warnings;
use strict;
use feature 'say';
use Expect;
my $cmd = 'ls -l ./ | head -5; sleep 3';
my $exp = Expect->spawn( $cmd );
say "Started process ", $exp->pid;
$exp->raw_pty(1);
$exp->log_stdout(0);
# ...
$exp->expect(undef);
say "Program exited with status ", $exp->exitstatus;
say $exp->before;
If no output is expected after the program goes incommunicado remove before
.
Another way is to set up a $SIGCHLD
signal handler, where you check for the program's PID and set a flag that other code can then check. The PID is in a variable which need be declared before the handler and then set with pid
method after the process is started, so that it is legal (under strict
) to use in the handler and it is set for when the handler runs.
Then exitstatus
isn't useful (-1
) as the process is reaped in the handler.
edited 7 hours ago
answered 19 hours ago
zdim
30.8k32040
30.8k32040
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53199828%2fwaiting-on-expect-until-spawned-program-completes%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Can you clarify your first sentence? Are you using perl's expect, or the plain Tcl expect and the spawned program is implemented in perl? Do you actually require expect for this task?
– glenn jackman
22 hours ago
Yes I'm using perl's expect. And the spawned program/task is basically a git clone of a remote repository. Now I'm unable to precisely tell when the cloning process is done and if I can proceed with the rest of my automation script
– seek
21 hours ago
1
If there is no interaction why use
Expect
? How is the program "inconsistent" -- what are other ways for it to finish, other than just exit?– zdim
19 hours ago