in reply to not waiting for external command to complete before getting the output

As an alternative to expect, here is a basic setup for IPC::Open3. You should be able to get the error thrown by cdrecord when you run this. Just put the reads in a while(1) loop, and check for your percentage done.
#!/usr/bin/perl use warnings; use strict; use IPC::Open3; my $pid = open3(\*WRITE, \*READ,0,"/usr/bin/cdrecord -v -dummy -eject +/mnt/my.iso"); #if \*ERROR is false, STDERR is sent to STDOUT #while(1){ #select(undef,undef,undef,.01); chomp(my $output = <READ>); print "$output\n"; #do some split and test to extract percentage #} waitpid($pid, 1); # It is important to waitpid on your child process, # otherwise zombies could be created.

I'm not really a human, but I play one on earth. flash japh
  • Comment on Re: not waiting for external command to complete before getting the output
  • Download Code

Replies are listed 'Best First'.
Re: Re: not waiting for external command to complete before getting the output
by Anonymous Monk on Apr 27, 2004 at 19:05 UTC
    Thanks guys for the help.

    I have tried all these solutions. None of them work. They all print the information I am wanting at the end of cutting the CD. I looked through the cdrecord code, and Jorg places a \r at the beginning of each line of output denoting how much of the cd has been cut. I tried removing those in perl, but to no avail either.
    What's really strange is if I redirect the output to a file, and then tail the file simultaneously, I get the information I am after. When I look at the file with VI, I see the following type of output:

    ^MTrack 01 0 of 47MB^MTrack 01 1 of 47MB^MTrack 01 2 of 47MB^M.....etc....

    This has the effect that each line indicating the percent of the track cut is over-written by the next line, creating that "nice" feeling of interactivity. I just find it's making my life hell.

    Also not sure that I fully understand how it can well be appending to a file on redirecting output from cdrecord, but not giving me the output when I pop the same in a perl script.
    Cheerio
    Hambo
      There is some information on dealing with these situations in "perldoc -q filehandle", about using sysread and ioctl. I'll try to get an example that works with cdrecord and post it later.

      I'm not really a human, but I play one on earth. flash japh