Solved

Backticks and while

Posted on 2008-10-29
4
257 Views
Last Modified: 2008-10-29
I am fairly new to perl and would like to know if the following would be ok, or if there was  a better way to do this. I tried open but $! gives me "No such file or directory" when the command works fine with either system or back ticks. also should I flush the data?
while(`$cmd`) {
print ".";
sleep(5);
}

Open in new window

0
Comment
Question by:lrudor
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 22837432
It's always best to describe what you are actually trying to do.

Perhaps, you want something like
open CMD, "/some/command|" or die "Can not run command $!\n";
 
while (<CMD>) {
  print;
  sleep(5);
}

Open in new window

0
 

Author Comment

by:lrudor
ID: 22837458
Tintin, thanks for your response.

here is the command that gets run:

"C:\video tools\mencoder\mencoder.exe" -sid 0 -vid 0 -nosound -o ./vid.264 -of rawvideo -ovc x264 -x264encopts bitrate=900:threads=auto:pass=1 -vf scale=704:400 -passlogfile ./pass.log -subfont-text-scale 3 "F:\videos\test.mkv"

so below returns:

"Unable to run the command. No such file or directory at"...

while system or backticks will run the command just fine.

my $cmd = '"C:\video tools\mencoder\mencoder.exe" -sid 0 -vid 0 -nosound -o ./vid.264 -of rawvideo -ovc x264 -x264encopts bitrate=900:threads=auto:pass=1 -vf scale=704:400 -passlogfile ./pass.log -subfont-text-scale 3 "F:\videos\test.mkv"';
 
print $cmd;
open CMD, $cmd or die "Unable to run the command. $!";
while (<CMD>) {
  print '.';
  sleep(5);
}

Open in new window

0
 
LVL 48

Accepted Solution

by:
Tintin earned 100 total points
ID: 22837490
You left out the most important part, the | symbol at the end of the command.  Appended to the command it means pipe the output, prepended means pipe to the input.

Again, I'll ask you to describe what you are trying to achieve.

Looking at your code, I suspect what you *really* want to do is output dots while you are encoding videos?  Correct?  If so, then I would suggest a completely different approach.
my $cmd = '"C:\video tools\mencoder\mencoder.exe" -sid 0 -vid 0 -nosound -o ./vid.264 -of rawvideo -ovc x264 -x264encopts bitrate=900:threads=auto:pass=1 -vf scale=704:400 -passlogfile ./pass.log -subfont-text-scale 3 "F:\videos\test.mkv"';
 
 
open CMD, "$cmd|" or die "Unable to run the command. $!";
while (<CMD>) {
  print '.';
  sleep(5);
}

Open in new window

0
 

Author Comment

by:lrudor
ID: 22837516
Sorry for being so vague in my description, but yes that's what I am trying to achieve, and how would you going about doing it? I was just trying to create something simple, its really the first time I have done anything in perl.
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

803 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