> Maxim Goncharov <[EMAIL PROTECTED]> said: > I ran into the problem with forking and I am not able to figure out what > happens. Here is the code (let's call the program server): > > $pid = open(HHH,"|- "); > if($pid){ > print HHH "something\n"; > }else{ > exec "client" > } > > Notice that I do not call close(HHH) because I want the parent just to > spawn the child, print something into it, and exit. And that is exactly > what happens. If I look at processes I see only client running, I can see > that client does get "something" from STDIN.
I do not think your code does what you think it does. fork() creates a duplicate process. Your parent process simply prints "something" and then exits. The child meantime just overlays itself with the "client" program. There is no communication between the parent and the child. If you want to do that, take a look at the pipe() function. Or for an easier option do it with a pipe open call. Something like (I've left some details out for clarity) open(CLIENT, "|client_program") || die "cannot run client - $!\n"; print CLIENT "something\n"; if (! close CLIENT) { print STDERR "client failed - $?\n"; } This code forks a child process which runs the "client_program" which reads from its STDIN the line the parent printed. Note the check on close. If the clients aborts then close returns 0 and sets $? to the client's exit code. -- Smoot Carl-Mitchell Consultant -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]