Link to home
Start Free TrialLog in
Avatar of oleber
oleberFlag for Portugal

asked on

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
Avatar of japhyRPI
japhyRPI

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.
Avatar of oleber

ASKER

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;
does ll expect user input? probably replace by ls -la
Avatar of oleber

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of smisk
smisk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial