how to capture output from a system call and pipe into running script?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • grikdog
    New Member
    • Mar 2007
    • 3

    how to capture output from a system call and pipe into running script?

    How to I capture stdout output from a system call and pipe it back into my running script?

    system "echo foobar";

    # how to continue here with "foobar" in stdin ??

    ...

    I can fake it with pipes and additional scripts, but that seems like overkill.

    Thanks.
    (Yes, I'm STILL a newbie!)

    dave
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    use backticks

    [CODE=perl]
    my $output = `echo foobar`;
    print $output; # Prints "foobar";
    [/CODE]

    - Miller

    Comment

    • grikdog
      New Member
      • Mar 2007
      • 3

      #3
      Yes indeed! Thank you!
      d

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        Originally posted by grikdog
        How to I capture stdout output from a system call and pipe it back into my running script?

        system "echo foobar";

        # how to continue here with "foobar" in stdin ??
        You can't. system() does not return stdout data back to your perl program. You can use backtiks as Miller has shown, but if you want to step through the output line by line, using a pipe is better.

        A more readable form of backtiks is the qx// operator.

        Comment

        • miller
          Recognized Expert Top Contributor
          • Oct 2006
          • 1086

          #5
          Hey Kevin,

          I'm continually annoyed whenever I want to refer people to the documentation for backticks. Instead of being at perldoc qx, you must instead go out of your way to perlop and search for qx. Is there any other location that you've found for such documentation?

          - Miller

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            Well, it's kind of buried on this page:

            perlop: quote and quote like operators

            qx is an operator, the operators are not given a page by page listing like the functions are.

            Comment

            • miller
              Recognized Expert Top Contributor
              • Oct 2006
              • 1086

              #7
              I still have to say .... lame.

              - M

              Comment

              • KevinADC
                Recognized Expert Specialist
                • Jan 2007
                • 4092

                #8
                Originally posted by miller
                I still have to say .... lame.

                - M

                I don't much care for it myself. It seems they could break down the operators into more specific categories and give them their own pages.

                Comment

                • miller
                  Recognized Expert Top Contributor
                  • Oct 2006
                  • 1086

                  #9
                  Well that's the thing. They already have pages for all the quoting operators. They simply link to the perlop page.

                  When referencing something, it's always useful to be able to provide a direct link. But the operators do not have specific anchors, so you have to do the "search for this" instruction. I think that while a lot of the operators are related and need to be discussed en mass, it would be very useful to newbies and us teachers to be able to link directly to the specific resource.

                  That's all :/

                  - M

                  Comment

                  Working...