Link to home
Start Free TrialLog in
Avatar of lrudor
lrudor

asked on

Backticks and while

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

Avatar of Tintin
Tintin

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

Avatar of lrudor

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lrudor

ASKER

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.