簡體   English   中英

禁用python記錄器輸出

[英]Disable python logger output

我有適用於Python 2.7.10的 python腳本,如下所示:

import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())
logger.info("Hello, world!");

是否可以通過某種方式在Windows機器上從Powershell運行此腳本使其不產生任何輸出? 我嘗試將輸出重定向到文件

C:\Python2.7\python.exe C:\Users\User\script.py > output.txt

但這沒有幫助,腳本寫的Hello, world! 要控制台的字符串。

您需要將所有輸出重定向到null:

command > nul 2>&1

要么

2> nul

殺死stderr

最后到輸出文件:

command > a.txt 2>&1

在Powershell中:

2>&1>$null
2>&1 | out-null

從:

https://serverfault.com/questions/132963/windows-redirect-stdout-and-stderror-to-nothing

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM