in reply to Re: I need some help with open2
in thread I need some help with open2

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.

Replies are listed 'Best First'.
Re^3: I need some help with open2
by Joost (Canon) on Dec 22, 2007 at 01:04 UTC
Re^3: I need some help with open2
by ikegami (Patriarch) on Dec 22, 2007 at 05:50 UTC

    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.