Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: qx not always capturing stdout

by Marshall (Canon)
on Mar 23, 2016 at 21:16 UTC ( #1158653=note: print w/replies, xml ) Need Help??


in reply to qx not always capturing stdout

Update: by popular demand, I strike this question myself...This qx thing is relatively new. What happens when you use the more traditional "backticks"?

Replies are listed 'Best First'.
Re^2: qx not always capturing stdout
by ikegami (Patriarch) on Mar 24, 2016 at 14:28 UTC

    `...` is just short for qx`...`, which is short for readpipe(qq`...`).

    $ perl -MO=Concise,-exec -e'`...`' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <$> const[PV "..."] s 4 <1> backtick[t1] vK 5 <@> leave[1 ref] vKP/REFC -e syntax OK $ perl -MO=Concise,-exec -e'qx`...`' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <$> const[PV "..."] s 4 <1> backtick[t1] vK 5 <@> leave[1 ref] vKP/REFC -e syntax OK $ perl -MO=Concise,-exec -e'readpipe(qq`...`)' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <$> const[PV "..."] s 4 <1> backtick[t2] vK/1 5 <@> leave[1 ref] vKP/REFC -e syntax OK

    This is by no means new; this has been the case for at least 18 years. (The oldest documentation I could find is perl5.005_53 from Oct 31st, 1998.)

Re^2: qx not always capturing stdout
by Paladin (Vicar) on Mar 23, 2016 at 21:35 UTC
    I'm not sure what your definition of relatively new is, but qx has existed since at least 5.8.8 (oldest Perldoc readily available on perldoc.perl.org) and 5.8.8 was released over 10 years ago (2006-Jan-31).
Re^2: qx not always capturing stdout
by StuLong (Acolyte) on Mar 23, 2016 at 21:20 UTC
    No change, same output. Or rather lack thereof.
      Found an example, where the daemonization closes STDOUT and STDIN in order to not create files. This could confuse the child process (which has no stdout). So either, maybe this works:

      use Daemon::Simple; open(SAVEIN, "<&STDIN"); open(SAVEOUT, "<&STDOUT"); Daemon::Simple::init("daemon"); open(STDIN, "<&SAVEIN"); open(STDOUT, "<&SAVEOUT"); print qx("/external/command"); close(STDIN); close(STDOUT);

      or you will have to redirect your output to a file

      qx("/external/command > /tmp/file")

      and read it back using open(), diamond and close()

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1158653]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2022-06-28 03:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (89 votes). Check out past polls.

    Notices?