[comp.lang.perl] Reading from STDOUT

shan_x@jhuvms.bitnet (08/23/90)

I'm writing a perl script to send file with FTP.
To determine the responses from the FTPD, I need to read 
from STDOUT.  I can do this  by redirecting STDOUT
to a file then read from the file. But this way I have
problem to synchronize the two processes. I have to put
"sleep(2)" everywhere.  Any better solutions?   Thanks.

X. Shan
shan@jhuvms.bitnet

libes@cme.nist.gov (Don Libes) (08/24/90)

In article <6182@jhunix.HCF.JHU.EDU> shan_x@jhuvms.bitnet writes:
>I'm writing a perl script to send file with FTP.
>To determine the responses from the FTPD, I need to read 
>from STDOUT.  I can do this  by redirecting STDOUT
>to a file then read from the file. But this way I have
>problem to synchronize the two processes. I have to put
>"sleep(2)" everywhere.  Any better solutions?   Thanks.

Since no one offered any Perl solutions, let me suggest using a
different tool.  (Is this a first for this newsgroup?)

I don't know what the rest of your Perl script is doing, but for the
part where you are interacting with ftp, consider using "expect" - a
tool specifically designed for controlling interactive programs.

Here is an expect fragment to send the file, foo.bar, and read the
response from ftp, reporting ftp's error if appropriate.

	send put foo.bar\r
	expect timeout {exit -1} *success*ftp>*

And yes, sigh, you can make this into one line if you want to.

Don