banner
李大仁博客

李大仁博客

天地虽大,但有一念向善,心存良知,虽凡夫俗子,皆可为圣贤。

nohup 後台運行python程式print無輸出

使用 nohup 後台運行 python,print 沒有輸出到日誌

nohup python foobar.py > foobar.log 2>&1 &

發現 foobar.log 中顯示不出來 python 程式中 print 的東西。這是因為 python 的輸出有緩衝,導致 foobar.log 並不能夠馬上看到輸出。python 有個 - u 參數,使得 python 不啟用緩衝。

nohup python -u foobar.py > foobar.log 2>&1 &

其他玩法:只輸出錯誤到日誌 # Only error write to log nohup python -u ./foobar.py> /dev/null 2>foobar.log & 不輸出到日誌 # Nothing to Display nohup python -u ./foobar.py> /dev/null 2>&1 & 全部 print 輸出到日誌 # Write all to log nohup python -u ./foobar.py> ./foobar.log 2>&1 &

https://blog.csdn.net/Statham\_stone/article/details/78290813

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。