From: xhoster on 28 Nov 2007 13:18 Mark <google(a)markginsburg.com> wrote: > I am reading piped output from a command that produces a lot of > output. I would like to terminate reading the data before the end of > the output is reached. > > The following sample program illustrates the issue. The program will > get stuck on the close(). Any help in dealing with this situation > will be appreciated. If you use a piped open, Perl automagically bundles the wait (or whatever the Windows equiv is) in with the close, which might be the problem. If you roll your own using pipe and fork (or Windows equiv), then it should be possible to unbundle the close and the wait. But why close, rather than just going about your business with an open but no longer used file handle? If you want the return value of the close, then anything you do to force the close to happen means that the return value you get will now be driven by the forcing method rather than the natural operation of the child, and so probably isn't worth having. Xho -- -------------------- http://NewsReader.Com/ -------------------- The costs of publication of this article were defrayed in part by the payment of page charges. This article must therefore be hereby marked advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate this fact.
From: Mark on 28 Nov 2007 16:09 On Nov 28, 10:18 am, xhos...(a)gmail.com wrote: > But why close, rather than just going about your business with an open but > no longer used file handle? If you want the return value of the close, > then anything you do to force the close to happen means that the return > value you get will now be driven by the forcing method rather than the > natural operation of the child, and so probably isn't worth having. > I tried removing the close() as you suggested but then the perl program hungs at the end of the program, presumably, while doing an implicit close.
From: xhoster on 28 Nov 2007 17:12 Mark <google(a)markginsburg.com> wrote: > On Nov 28, 10:18 am, xhos...(a)gmail.com wrote: > > > But why close, rather than just going about your business with an open > > but no longer used file handle? If you want the return value of the > > close, then anything you do to force the close to happen means that the > > return value you get will now be driven by the forcing method rather > > than the natural operation of the child, and so probably isn't worth > > having. > > > > I tried removing the close() as you suggested but then the perl > program hungs at the end of the program, presumably, while doing an > implicit close. So I assume you find that undesirable? :) The same thing happens if a lexically held find handle goes of scope, so this implicit close could get you in that case to. And if I capture the pid and then kill it before the close, the close doesn't hang but doing this seems to leave some kind of CPU-draining zombies behind. Ugg. I'm glad I don't need to program in Perl for Windows very much. Xho -- -------------------- http://NewsReader.Com/ -------------------- The costs of publication of this article were defrayed in part by the payment of page charges. This article must therefore be hereby marked advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate this fact.
First
|
Prev
|
Pages: 1 2 Prev: Failed with exit code 65280. Next: incorrect errno/perror with IO::socket->new |