standard output issue when launching a child script

Discussion in 'Perl Misc' started by Sherm Pendley, Jun 19, 2005.

  1. "erik" <> writes:

    > sub odie_qa_integration{
    > qx(/var/apache/cgi-bin/odie-qa.pl device="$device");
    > }
    >
    > I am running a master script that displays results to standard out. But
    > when I launch a child script as shown above, all the output is hidden.


    It's not hidden, it's returned from the qx() operator. If you want to
    print that, just print it:

    print qx(/blah/blah);

    Have a look at "perldoc perlop", especially the section titled "Quote
    and Quote-like Operators".

    sherm--
     
    Sherm Pendley, Jun 19, 2005
    #1
    1. Advertising

  2. Sherm Pendley

    erik Guest

    sub odie_qa_integration{
    qx(/var/apache/cgi-bin/odie-qa.pl device="$device");
    }

    I am running a master script that displays results to standard out. But
    when I launch a child script as shown above, all the output is hidden.
    How can I make the output of the child output the same as the parent
    script?
     
    erik, Jun 19, 2005
    #2
    1. Advertising

  3. Sherm Pendley

    erik Guest

    Thanks a million. I was about to explore filehandles before I read
    your post.

    Thanks again.
     
    erik, Jun 19, 2005
    #3
  4. erik wrote:
    > sub odie_qa_integration{
    > qx(/var/apache/cgi-bin/odie-qa.pl device="$device");
    > }
    >
    > I am running a master script that displays results to standard out.
    > But when I launch a child script as shown above, all the output is
    > hidden.


    Well, no, not exactly. It's more like you are capturing it and then never
    ever use it again because you forgot to assign it to a variable in the first
    place.
    From "perldoc perlop":

    qx/STRING/
    `STRING`
    A string which is (possibly) interpolated and then executed as a
    system command with "/bin/sh" or its equivalent. [...]. The
    collected standard output of the command is returned; [...]

    > How can I make the output of the child output the same as the
    > parent script?


    If you don't want to capture the output then don't tell Perl to capture it
    but use the proper function for that purpose. Details see 'perldoc -f
    system'.

    jue
     
    Jürgen Exner, Jun 19, 2005
    #4
  5. Sherm Pendley wrote:
    > "erik" <> writes:
    >
    >> sub odie_qa_integration{
    >> qx(/var/apache/cgi-bin/odie-qa.pl device="$device");
    >> }
    >>
    >> I am running a master script that displays results to standard out.
    >> But when I launch a child script as shown above, all the output is
    >> hidden.

    >
    > It's not hidden, it's returned from the qx() operator. If you want to
    > print that, just print it:
    >
    > print qx(/blah/blah);


    Ouch! If you don't want to capture the program output, then don't use a
    function that captures it.
    system() is a much better solution for the OP than to capture the output and
    then print it.

    jue
     
    Jürgen Exner, Jun 19, 2005
    #5
  6. Sherm Pendley

    erik Guest

    sub odie_qa_integration{
    print "$device";
    print qx(/var/apache/cgi-bin/odie-qa.pl device='a.callahan.com');
    }

    The print function works great. My other issue is that I cannot argv0
    to the child script. I have tried double quotes, no quotes, single
    quote. Above I put in a static device name to see what happens and it
    fails too. The child script says you gave me "" as a device name. So
    that is getting lost from parent to child.
     
    erik, Jun 25, 2005
    #6
  7. Sherm Pendley

    erik Guest

    Something else to note, when I use back ticks and run it from CLI,
    rather than running the CGI from the browser, it works great.

    So this:

    sub odie_qa_integration{
    print `/var/apache/cgi-bin/odie-qa.pl device=$device`;
    }

    way of calling the child script works great from CLI. But in the
    browser, the child script still says "device not found" meaning the
    parent did not pass the $device to it. If I remove $device and put in a
    static device name, I get the same thing. So why would the browser
    interface not work but CLI does. Why does any variable passed to
    odie-qa.pl, via a browser, get lost.

    p.s. I also tried system instead of "print qx" and it behaves the same
    way.
     
    erik, Jun 25, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Rodriguez
    Replies:
    23
    Views:
    1,212
    David Schwartz
    Dec 9, 2003
  2. Graham Nicholls

    Launching pdb from within a script

    Graham Nicholls, Jan 4, 2004, in forum: Python
    Replies:
    8
    Views:
    324
    Peter Hansen
    Jan 6, 2004
  3. Ernesto
    Replies:
    6
    Views:
    600
    Magnus Lycka
    Sep 13, 2005
  4. Replies:
    1
    Views:
    309
    Knute Johnson
    Mar 26, 2009
  5. Venks
    Replies:
    5
    Views:
    280
    Ken Bloom
    Dec 6, 2007
Loading...

Share This Page