in reply to IPC::open3 obfuscification

<> blocks until a newline is received, so your program hangs if the client waits for input after sending two lines in a row to STDERR. You can also run into problems if the child's STDOUT is buffered.

Replies are listed 'Best First'.
Re^2: IPC::open3 obfuscification
by tilly (Archbishop) on Dec 17, 2008 at 02:42 UTC
    That is another possibility, and made me think of the following hackish solution that does what the original code was meant to:
    system("yes yes | cleartool setcs $CS_FILENAME 2> /dev/null");
    (This assumes Unix.)

    If you want more flexible error handling you need to go down the other paths I suggested.

Re^2: IPC::open3 obfuscification
by Dcole (Initiate) on Dec 17, 2008 at 02:45 UTC
    It will be nearly impossible for me use an API. There is a lot of legacy code surrounding this snippet. Is it possible to redirect STDERR to STDOUT and do a pattern match on the phrases I would want to send "yes" to, will that work? My other question is - once STDERR has something in it, does the process continue? I tried just sending "yes" to the input after every line, however, my program still hung after a bit. Almost like once STDERR had something in it, STDOUT got nothing, and thus, the snapshot update also stopped.
      Redirecting is possible, but is very likely to create buffering issues. Printing after every line can cause possible problems if either there are buffering issues, or if 2 questions are asked in a row. There is also the possibility that at some point it asks a non-yes/no question, in which case you need more logic. Try my suggested hack, if that fails you should be able to see the question it trips up on.

      About using an API, I know what legacy code can be like but you still can do it. Just put a well-named function call in that line, and go off to write your function somewhere however is best. Then the legacy code is no worse, and you're free to write that function however you see best.

        So, I am not entirely sure this fixed the problem, but I am optomistic, so I'm going to go ahead and say i fixed it. I redirected output to /dev/null, and I sent my 'yes' to prompts in to STDERR, instaed of STDIN. I don;t know why thye would have done it like that..but..it seems to be the issue. I'll be posting again if that fails to be the answer, haha