Solved

Get output from a program

Posted on 2002-05-10
6
118 Views
Last Modified: 2010-03-05
I need the output of a program.

something like

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

that produce the some output that ll comand
0
Comment
Question by:oleber
6 Comments
 
LVL 1

Expert Comment

by:japhyRPI
ID: 7001657
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
 
LVL 10

Author Comment

by:oleber
ID: 7001687
perl -e 'my $a = qx[ll]; print $a;'

this didn't work for me. No output from the program
0
 
LVL 1

Expert Comment

by:japhyRPI
ID: 7001695
What is the program?  Did you check $! for an error message?

  my $output = qx[ll] or warn "couldn't run ll: $!";
  print $output;
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 51

Expert Comment

by:ahoffmann
ID: 7002968
does ll expect user input? probably replace by ls -la
0
 
LVL 10

Author Comment

by:oleber
ID: 7013266
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
 
LVL 1

Accepted Solution

by:
smisk earned 50 total points
ID: 7014474
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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now