• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 134
  • 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
0
oleber
Asked:
oleber
1 Solution
 
japhyRPICommented:
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.
0
 
oleberAuthor Commented:
perl -e 'my $a = qx[ll]; print $a;'

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

  my $output = qx[ll] or warn "couldn't run ll: $!";
  print $output;
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
ahoffmannCommented:
does ll expect user input? probably replace by ls -la
0
 
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.
0
 
smiskCommented:
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: $!";
0
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

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.

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