> -----Original Message----- > From: Prahlad Vaidyanathan [mailto:[EMAIL PROTECTED]] > Sent: Friday, January 11, 2002 4:52 AM > To: [EMAIL PROTECTED] > Cc: Michael Fowler > Subject: Re: why does open()ing happen only at the <FD> line ? > > > Hi, > > On Thu, 10 Jan 2002 Michael Fowler spewed into the ether: > [-- snip --] > > Um, how do you figure? The sudo program prints out the > "Password:" prompt, > > and from your output you can clearly see "test" is after > "Password:". So > > sudo is being run before "test" is printed. > > Yes, I noticed that _just_ after I posted. This is kinda > weird, but the > test case behaves differently at different points in time. > > Sometimes, 'test' is printed, and only then the sudo prompt > appears. At > other times, the sudo prompt appears, 'test' is printed, and > it waits at > the next line for the password (like my post yesterday).
There are two separate processes writing to your terminal. One, the sudo, writes "Password", while the other writes "test". In the absence of an explicit syncronization mechanism, there is no way to guarantee which one will run first. > > ie. > > <test1> > $ ./test.pl > test > Password:[waits for password] > .... > </test1> > > <test2> > $ ./test.pl > Password:test > [waits for password] > .... > </test2> > > I'm guessing this has to do with how long it takes to invoke > sudo (given > system load, etc). But, all the same, shouldn't it wait for > the password > to be entered _before_ printing 'test' ? Now I'm totally stumped. The process that "waits for the password" is different from the process that prints "test". You didn't tell the second to wait for the first, so it doesn't wait. If you want your script to wait until sudo has completely finished, you need to use system(), backticks, or wait(). These wait for the child process to finish. fork() and pipe open() do not wait (But close() on the handle from pipe open() *does* wait). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]