• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 130
  • Last Modified:

Get output from a program

I need the output of a program.

something like

$comandOutput = execute("ll");
print $comandOutput

that produce the some output that ll comand
1 Solution
Use backticks or qx():

  $output = `command`;  # one big string
  @output = `command`;  # list of lines
  $output = qx[command];  # one big string
  @output = qw[command];  # list of lines

You can also use open(), but the above should be sufficient.
oleberAuthor Commented:
perl -e 'my $a = qx[ll]; print $a;'

this didn't work for me. No output from the program
What is the program?  Did you check $! for an error message?

  my $output = qx[ll] or warn "couldn't run ll: $!";
  print $output;
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

does ll expect user input? probably replace by ls -la
oleberAuthor Commented:
The problem is that I'm using a old version of Perl (5.005_03 for sun4-solaris), in windows with a newer version all solucitons works.
Here's a different way, using a routines similar to popen() in C.  Backticks are much neater, but try this on your perl distribution :

#! /usr/local/bin/perl

open(FP, "ls -la |") || die "open: $!";
@lines = <FP>;
print @lines;
close(FP) || die "close: $!";
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now