How to store output into variable in perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • priyankapendkar
    New Member
    • Apr 2011
    • 9

    How to store output into variable in perl

    Hi,

    Output of "ps -o etime,time,pcpu ,pmem,fname -C sbd-java"
    command is -
    Elapsed Time %cpu %MEM COMMAND
    02:14:03 00:03:28 2.5 6.3 sbd-java

    In shell script-(when i run below code)
    X=`ps -o etime,time,pcpu ,pmem,fname -C sbd-java --no-heading|awk '{print $3 }'`;

    echo $X

    output-2.5

    i want use same application in perl script.
    Is their any change required in above code.i have tried usind the same code in perl but its not working...)

    can you plz tell me what changes need to be do??
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    Just use backticks

    Code:
    my $results = `ps -o etime,time,pcpu,pmem,fname -C sbd-java`;

    Comment

    Working...