in reply to Capturing STDERR with a pipe

You didn't actually say for certain whether "myprogram" also writes data to STDOUT as well as STDERR -- and if so, whether you want to keep both sets of data. Here are three scenarios, with suggestions for each (assuming a standard bourne-style shell is invoked by the "open" call):

You would need to read the part about redirection in the "sh" or "bash" man page to understand (or at least see examples of) the ordering of the redirection operators and their various meanings.