Perl 无法正确打印
好的,所以我有一些类似于您在下面看到的子例程,我的问题是打印函数在实际命令完成之前不会打印出来,我希望它打印
“Has MySQL,正在安装:”,然后执行命令然后打印 OK。我已经尝试过使用 sleep 并尝试清除 $ssh_d 对象。任何建议表示赞赏。不要担心这个特定子系统中的变量,问题到处都在发生。谢谢你们。
if ($MySQL)
{
print "Has MySQL, Installing: ";
$mysqlCmd = "/path/to/script/mysql-install.pl $person > /dev/null 2>&1";
$ssh_d->cmd("$mysqlCmd");
print "OK\n";
}
Ok, so I have some sub routines similar to what you see below, my issue is that the print function is not printing out until the actual command is complete, I want it to print
"Has MySQL, Installing:", and then do the command then print OK. I have already tried using sleep and tried clearing the $ssh_d object. Any advice appreciated. Don't worry about the variables in this particular sub, the issue is happening all over. Thanks guys.
if ($MySQL)
{
print "Has MySQL, Installing: ";
$mysqlCmd = "/path/to/script/mysql-install.pl $person > /dev/null 2>&1";
$ssh_d->cmd("$mysqlCmd");
print "OK\n";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
STDOUT 通常是行缓冲的,因此在打印换行符之前您不会看到输出。您可以在打印之前设置
$|
以强制打印输出。要在每次打印后打开自动刷新,请将
$|
设置为 1:(请注意,$| 实际上并不是单个值,它是针对每个文件句柄单独跟踪的。设置它时,它会影响当前选定文件句柄的设置(请参阅
选择
)。STDOUT is usually line-buffered, so you won't see your output until you print a newline. You can set
$|
before printing to force your output to be printed.To turn on autoflushing after each print, set
$|
to 1:(Note that $| isn't actually a single value, it is tracked separately for each filehandle. When you set it, it affects the setting for the currently selected filehandle (see
select
).这个可以吗?
Will this do?