目前在bash终端依次执行如下三条命令:
1:
php test.php >> test.log
2:
python test.py >> test.log
3:
sh test.sh >> test.log
并且在另一个窗口执行:
tail -f test.log
其中1 php和3 bash可以实时在test.log中写入,
但是为什么python只会在python程序结束之后才会在test.log中写入?
并且像这样:
echo "cd $test_dir && /usr/bin/python test.py &" >> test_py.sh && sh test_py.sh
将python放入sh脚本中执行也不行
附:
1 test.php
$i = 1;
while (True) {
sleep(1);
print $i++ . "\r\n";
if ($i > 10) {
break;
}
}
?>
2 test.py
#!/usr/bin/python
# coding=utf-8
import time
i = 1
while True:
i += 1
print i
time.sleep(1)
if i > 10:
break
print "----------end-----------"
3 test.sh
#!/usr/bin/env bash
# cd /Users/cg/MyFiles/test && /usr/bin/python cgcg.py &
i=1
while [[ 1 ]]; do
sleep 1
i=`expr $i + 1`
echo $i
done