getting shell outputs as variables

P

Peter

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
 
G

Gunnar Hjalmarsson

Peter said:
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.
 
P

Peter

Gunnar said:
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.
 
J

James K

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.
 
J

James K

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top