getting shell outputs as variables

Discussion in 'Perl Misc' started by Peter, Sep 28, 2003.

  1. Peter

    Peter Guest

    My script runs a program which outputs various information and i need to
    sort through that info and store some of it as a variable.
    When the program finishes (mencoder)... this is what it spits out to the
    console.

    Recommended video bitrate for 650MB CD: 16021
    Recommended video bitrate for 700MB CD: 17264
    Recommended video bitrate for 800MB CD: 19749
    Recommended video bitrate for 2 x 650MB CD: 32175
    Recommended video bitrate for 2 x 700MB CD: 34661
    Recommended video bitrate for 2 x 800MB CD: 39631

    Video stream: 0.767 kbit/s (95 bps) size: 32380 bytes 337.539 secs
    8095 frames

    Audio stream: 117.333 kbit/s (14666 bps) size: 4957920 bytes 338.040
    secs

    I need to get the "4957920" bytes value from the audio line and the
    "337.539" seconds value from the audio stream line and store them as
    some variables. Any help is appreciated
    Thanks
    Peter, Sep 28, 2003
    #1
    1. Advertising

  2. Peter wrote:
    > My script runs a program which outputs various information and i
    > need to sort through that info and store some of it as a variable.
    > When the program finishes (mencoder)... this is what it spits out
    > to the console.
    >
    > Recommended video bitrate for 650MB CD: 16021
    > Recommended video bitrate for 700MB CD: 17264
    > Recommended video bitrate for 800MB CD: 19749
    > Recommended video bitrate for 2 x 650MB CD: 32175
    > Recommended video bitrate for 2 x 700MB CD: 34661
    > Recommended video bitrate for 2 x 800MB CD: 39631
    >
    > Video stream: 0.767 kbit/s (95 bps) size: 32380 bytes 337.539 secs 8095 frames
    >
    > Audio stream: 117.333 kbit/s (14666 bps) size: 4957920 bytes 338.040 secs
    >
    > I need to get the "4957920" bytes value from the audio line and the
    > "337.539" seconds value from the audio stream line and store them
    > as some variables.


    So, then post the code you have, showing us how you have been dealing
    with the task so far.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Sep 28, 2003
    #2
    1. Advertising

  3. Peter

    Peter Guest

    Gunnar Hjalmarsson wrote:
    > Peter wrote:
    >
    >> My script runs a program which outputs various information and i
    >> need to sort through that info and store some of it as a variable.
    >> When the program finishes (mencoder)... this is what it spits out
    >> to the console.
    >>
    >> Recommended video bitrate for 650MB CD: 16021
    >> Recommended video bitrate for 700MB CD: 17264
    >> Recommended video bitrate for 800MB CD: 19749
    >> Recommended video bitrate for 2 x 650MB CD: 32175
    >> Recommended video bitrate for 2 x 700MB CD: 34661
    >> Recommended video bitrate for 2 x 800MB CD: 39631
    >>
    >> Video stream: 0.767 kbit/s (95 bps) size: 32380 bytes 337.539
    >> secs 8095 frames
    >>
    >> Audio stream: 117.333 kbit/s (14666 bps) size: 4957920 bytes
    >> 338.040 secs
    >>
    >> I need to get the "4957920" bytes value from the audio line and the
    >> "337.539" seconds value from the audio stream line and store them
    >> as some variables.

    >
    >
    > So, then post the code you have, showing us how you have been dealing
    > with the task so far.
    >

    Well..i'm not really sure how to do it. New to perl and the perl docs
    are huge. I think i need to use something like
    $probe_output =~ and this part i don't know;
    not really sure where to look either.
    i saw something else like @a = 'my command to start the program';
    which would load all of that output data into an array..but i still need
    to filter through it.
    Peter, Sep 28, 2003
    #3
  4. Peter

    James K Guest

    On Sat, 27 Sep 2003 19:47:51 -0400, Peter wrote:

    > My script runs a program which outputs various information and i need to
    > sort through that info and store some of it as a variable.
    > When the program finishes (mencoder)... this is what it spits out to the
    > console.
    >
    > Recommended video bitrate for 650MB CD: 16021
    > Recommended video bitrate for 700MB CD: 17264
    > Recommended video bitrate for 800MB CD: 19749
    > Recommended video bitrate for 2 x 650MB CD: 32175
    > Recommended video bitrate for 2 x 700MB CD: 34661
    > Recommended video bitrate for 2 x 800MB CD: 39631


    my @slurp = `mencoder $param1 $param2`;

    @slurp will then hold an array of lines. Foreach your way through them to
    find what you need.
    James K, Sep 28, 2003
    #4
  5. Peter

    James K Guest

    On Sat, 27 Sep 2003 20:34:43 -0400, Peter wrote:
    > Well..i'm not really sure how to do it. New to perl and the perl docs
    > are huge. I think i need to use something like
    > $probe_output =~ and this part i don't know;
    > not really sure where to look either.
    > i saw something else like @a = 'my command to start the program';
    > which would load all of that output data into an array..but i still need
    > to filter through it.


    First, those should be backticks. `` as opposed to ''

    Second, go to:
    http://learn.perl.org/library/beginning_perl/

    And read chapters 4 & 5 (and possibly 1, 2, and 3). Even better, buy a
    printed copy while you're there.
    James K, Sep 28, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    5,643
    Jonathan Bromley
    Feb 18, 2005
  2. Christian Heimes
    Replies:
    0
    Views:
    580
    Christian Heimes
    Feb 27, 2008
  3. Gerardo Herzig
    Replies:
    1
    Views:
    1,055
    Philipp Pagel
    Feb 27, 2008
  4. D'Arcy J.M. Cain
    Replies:
    0
    Views:
    842
    D'Arcy J.M. Cain
    Feb 27, 2008
  5. Samuel A. Falvo II
    Replies:
    0
    Views:
    469
    Samuel A. Falvo II
    Oct 8, 2008
Loading...

Share This Page