jcpunk has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,
I need to develope a regular expression for testing if a prompt was found (did spawn(/bin/sh) succeed) I am currently using the Expect module to do this and was wondering if anyone had any thoughts on what sort of reg ex would suffice for this as my current one qr'[\]\$\>\#]\s\$\%' does not do the job. Might I enlist your aid in this?

Replies are listed 'Best First'.
Re: reg ex and the prompt
by pzbagel (Chaplain) on Jun 03, 2003 at 19:42 UTC

    Why not check the return value of spawn?

    $test=Expect->spawn("/bin/sh") || die "Can't spawn /bin/sh:$!";

    On a side note, shell prompts are completely configurable, they can go from:

    #

    to

    [ user@host: 10:15pm: 12 ] ~/docs >

    You'll need to be more specific as what you think the prompts will look like to generate a better regex.

    HTH

Re: reg ex and the prompt
by arthas (Hermit) on Jun 03, 2003 at 19:45 UTC

    The regex you need depends on the prompt. The following expression should however work in most cases:

    $prompt =~ /[$%#>] $/;

    Michele.

Re: reg ex and the prompt
by fglock (Vicar) on Jun 03, 2003 at 19:32 UTC

    You could try something simpler, first. The prompt might not be what you are expecting:

    [\]\$\>\#]\s

      Why all that backwhacking?

      Something like /[]$#%>]\s*$/ will probably work in most cases. (I hate to even include a ']' in there but some people use it.) For /bin/sh, $ and # are by far the most common prompt endings, with or without following space.

      -sauoq
      "My two cents aren't worth a dime.";
      
Re: reg ex and the prompt
by tedrek (Pilgrim) on Jun 04, 2003 at 02:36 UTC
    as pzbagel suggested check the return of spawn to see if it worked. Then if you will still need to match the prompt later just set it yourself that way you know what it will be. send "PS1='PROMPT$'" to the shell to set it.