Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Copy terminal lines-unix

by Corion (Patriarch)
on Oct 06, 2015 at 08:51 UTC ( [id://1143895]=note: print w/replies, xml ) Need Help??


in reply to Copy terminal lines-unix

See the backticks:

my $output = `ls`;

You cannot read terminal output after the fact from Perl, but you can paste the terminal output into Perl:

while( <> ) { chomp; print "You pasted: [$_]\n"; };

Replies are listed 'Best First'.
Re^2: Copy terminal lines-unix
by baxy77bax (Deacon) on Oct 06, 2015 at 09:39 UTC
    agree. but what about the cases when I need to pass and execute something like this:
    ./SaveCMD "ls | perl -lne 'print $_ if /-/'" --SaveCMD-- #!/usr/bin/perl use strict; open(OUT, ">>", "cmd-out") || die "$!"; print OUT "cmd: $ARGV[0] \n"; my $cmd = $ARGV[0]; print STDERR $cmd; my $out = qx($cmd); print OUT $out; close OUT;
    in such situations I am not free to use $_ variable. any way to bypass this??

      What makes you think that you are not free to use $_ in this situation?

      Maybe now it's a good time to learn about Perl, its syntax, especially about loops?

      If you need to escape the dollar sign to prevent its expansion by the shell, use a backslash:
      ./SaveCMD "ls | perl -lne 'print \$_ if /-/'"
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-03-28 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found