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










share|improve this question























  • 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














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










share|improve this question























  • 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












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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 use Expect? 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










  • 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















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












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.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    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.






    share|improve this answer


























      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.






      share|improve this answer
























        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.






        share|improve this answer














        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 7 hours ago

























        answered 19 hours ago









        zdim

        30.8k32040




        30.8k32040



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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














































































            Popular posts from this blog

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            Crossroads (UK TV series)

            ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế