Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Expect.pm and multiline commands

by cbrandtbuffalo (Deacon)
on Sep 28, 2006 at 13:28 UTC ( [id://575348]=perlquestion: print w/replies, xml ) Need Help??

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

In a typical unix shell, you can type a multiline command using \, that is:
shell>some -really -long -command 'string\ more string stuff'
I'm trying to build a test using Test::Expect, but I'm finding it hard to duplicate the above.

I tried a few variations and
expect_send(qq{some -command 'string stuff\\ \cM more on next line'}, +"Testing...");
seems to send the right stuff, escaping and sending a '\', then a newline. But I think Expect.pm is getting confused because it seems to treat the second part of the command as the expected output.

Is there a standard way to do this? Who's getting confused, Test::Expect, Expect::Simple, or Expect.pm?

Update:One other question: even if I get this working, will this test only work in some shells? That is, if I wanted it to be multi-platform, would I need multiple versions of the test?

Update:Modified example to show that the newline is inside a quoted string.

Thanks for any suggestions.

Replies are listed 'Best First'.
Re: Expect.pm and multiline commands
by Tomte (Priest) on Sep 28, 2006 at 13:48 UTC

    IIRC

    shell>some -really -long -command \ -with -many -options

    is actualy one line - the newline character is consumed and not part of the executed command.

    compare

    tomte@librics-tomte ~ $ echo "test eins" test eins
    to
    tomte@librics-tomte ~ $ echo "test\ eins" testeins

    regards,
    tomte


    An intellectual is someone whose mind watches itself.
    -- Albert Camus

      I should clarify my example because the case I'm trying to test actually matches your example. That is, I want to test a string passed to an option and the string should pass along the new line.

      I think your example may have answered my question about different shells. I use tcsh and I get:
      >echo "test\ ? stuff" test stuff >echo "test Unmatched ".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://575348]
Approved by Hue-Bond
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2024-04-23 14:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found