Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: Reading output of external program without Shell

by karlgoethebier (Abbot)
on Nov 15, 2017 at 19:08 UTC ( [id://1203506]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Reading output of external program without Shell
in thread Reading output of external program without Shell

Thanks for your kind reply. BTW, as far as i vaguely remember this doesn't call a shell:

#!/usr/bin/env perl use strict; use warnings; use IPC::Run qw( run ); use feature qw(say); my $command = q(cat); my $text = run qq($command $0); say $text; __END__

Best regards, Karl

«The Crux of the Biscuit is the Apostrophe»

perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Replies are listed 'Best First'.
Re^4: Reading output of external program without Shell
by haukex (Archbishop) on Nov 15, 2017 at 20:38 UTC
    this doesn't call a shell

    The code you showed does, but if you give run an arrayref, it does not (at least on *NIX):

    $ perl -wMstrict -MIPC::Run=run -e' run "pstree -A $$" ' perl---sh---pstree $ perl -wMstrict -MIPC::Run=run -e' run ["pstree","-A",$$] ' perl---pstree
      "The code you showed does..."

      Ah, right. Thanks for correcting me. A precious hint.

      BTW, from the friendly manual:

      # Launch a sub process directly, no shell. Can't do redirection # with this form, it's here to behave like system() with an # inverted result. $r = run "cat a b c";

      Perhaps i missed something.

      "Es ist immer komplizierter" (Ludwig Marcuse)

      Still my favorite quote and motto.

      Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

      perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

        Hm, you're right, it does say that!

        # Call this system's shell, returns TRUE on 0 exit code # THIS IS THE OPPOSITE SENSE OF system()'s RETURN VALUE run "cat a b c" or die "cat returned $?"; # Launch a sub process directly, no shell. Can't do redirection # with this form, it's here to behave like system() with an # inverted result. $r = run "cat a b c";

        I don't see how run would know that it is being called as run() or die vs. $r = run(). Also, I can't get it to work...

        $ perl -wMstrict -MIPC::Run=run -e' my $r = run "pstree -A $$" ' perl---sh---pstree

        Later on the docs say:

        run(), start(), and harness() can all take a harness specification as input. A harness specification is either a single string to be passed to the systems' shell

        And, on the other hand, the IPC::Run docs don't explicitly say that run [...] doesn't use the shell, although in the code you can find exec { $_[0] } @_;. It's all a bit confusing unfortunately.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-23 22:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found