LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 599|回复: 2

请教一个关于Perl和其他程序沟通的问题。。。

[复制链接]
发表于 2004-12-29 21:25:07 | 显示全部楼层 |阅读模式
假设另一个程序叫aaa,它的源代码不可见。单独执行aaa的时候,它会给出提示,要求用户输入。
为了更直观一些,下面我演示一下执行aaa的过程。
$aaa
Please input the first num: 111 (回车)
Please input the second num:222 (回车)

好,大致就是这样的。(111和222是我输入的)
现在,如果用Perl来完成输入111和222的过程:
open(SM,"|aaa") or die "....";
print SM "111\n";
print SM "222\n";

问题来了:由于aaa执行很慢或者其它什么原因,在屏幕上的输出是这样的:
111
222
Please input the first num:
Please input the second num:

aaa的确是正确地获得了Perl给它的输入,但本人更希望整个输出就象是我手动输入一样——因为这个输出文件还需要交给另一个程序分析,所以才这样希望来着。
望大家不吝赐教! :p
发表于 2005-1-1 10:59:52 | 显示全部楼层
open(SM,"|aaa") or || die "can't fork aaa: $!";
while (<SM>) {
if .......
}
close(SM)|| die "can't close aaa: $!";
 楼主| 发表于 2005-1-4 11:05:47 | 显示全部楼层
Post by alchemy
open(SM,"|aaa") or || die "can't fork aaa: $!";
while (<SM>) {
if .......
}
close(SM)|| die "can't close aaa: $!";


这样不能避免我之前所说的问题。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表