在装有mysql和apache的Mac上,以下perl测试脚本有一个奇怪的问题:
# stop all servers
`mysql.server stop 2>&1`;
`apachectl -k graceful-stop 2>&1`;
is apache_is_running(), 0, 'determines if apache is not running';
`apachectl -k start 2>&1`;
is apache_is_running(), 1, 'determines apache is running';
is mysql_is_running(), 0, 'determines mysql is not running';
system "mysql.server start 2>&1";
is mysql_is_running(), 1, 'determines mysql is running';
print "hi\n";
exit;
使用prove -l --verbose
运行测试时,得到以下输出:
1..4
# Running my tests
ok 1 - determines if apache is not running
ok 2 - determines apache is running
ok 3 - determines mysql is not running
Starting MySQL
. SUCCESS!
ok 4 - determines mysql is running
hi
然后,测试只会挂起,并且永远不会完全退出。关于导致该问题的最后一个命令的原因:system "mysql.server start 2>&1";
我尝试使用反引号而不是system
,但这没有帮助。如果我执行了最后一条命令,它会正常退出。
答案 0 :(得分:0)
好的,这是解决问题的方法,但是我仍然不清楚原因:
`mysql.server start >/dev/null 2>&1`;