in reply to I need some help with open2

Why and what are you printing to SOXOUT? IOW why are you printing anything to SOXOUT and extrapolating from that why are you using open2 at all?

Removing the print SOXOUT $buf; line seems to fix the issue as far as I'm able to reproduce it.

As far as I can see it looks like you're misunderstanding the sox interface.

..

Replies are listed 'Best First'.
Re^2: I need some help with open2
by Anonymous Monk on Dec 22, 2007 at 00:26 UTC
    This is just an example code. This is part of a bigger project. I just wanted to make things a little more simple so I just took out the problem area and posted it here. When i run this code it does not work with any file greater then 16K, I don't know why. I think it may have to do something with buffers but I tried using syswrite and sysread but it doesn't help.

      If sox is sending you data and you're not reading it, the pipe will fill up and sox will block trying to print to the pipe.

      One bug: You never call waitpid to cleanup the zombie child process.

      Another bug: You pass user-provided text the shell without (usefully) validating it and without escaping it.
      "sox -t $type - -s -r 8000 -w -t wav - 2>/dev/null"
      should be
      "sox -t \Q$type\E - -s -r 8000 -w -t wav - 2>/dev/null"

      You should probably flush your pipe after writing to it (or turn on autoflushing on it).

      Update: I had the sox and the parent program mixed up. Fixed.