From: Name Name Date: 2006-07-12T05:14:03+09:00 Subject: Re: Processes and Portability I want this to be portable, ie not just *nix, so I can't fork. However, I am doing something similar to forking in terms of getting the pid which popen will do. I'm sure if I used fork (which I can't) on program > logfile, it won't be the pid of program (or it might be, i'm not sure, but the point is, the logic is messed up since I am doign the extra redirecting) Yohanes Santoso wrote: > Name Name writes: > >> a=IO.popen("program > logfile"), but on Windows this creates two >> processes, cmd.exe and program. a.pid only gives the pid of cmd.exe. >> And the behavior on *nix seems to be just the program (although I can be >> wrong). > > The behaviour in *nix depends on your /bin/sh. Some shells gives the > child's pid, other gives the pid of itself. > > pdksh gives the pid of itself. > bash gives the pid of the child (the behaviour you wanted). > Don't know about other shells. > > The lesson here, you can't get the pid of the child consistently > unless you do the forking yourself. > > YS I know that Harmen. I want the pid of not the intermediate shell, which is the one I am getting back with popen. I want the pid of the program itself that I opened. Also, program does produce output and logfile is writeable, and I need this to run on any system. >On Linux that should work if program 'progam_name' produces output and >file 'logfile' is writable. One of the two processes you mentioned is an >intermediate shell by the way. >Harmen -- Posted via http://www.ruby-forum.com/.