![](/img/trans.png)
[英]Jenkins: print a Hyperlink (HyperlinkNote) in console output from a script
[英]Print colorized output - working from console but not from script
我有一個奇怪的問題,我不能把手指放在上面。 有一個程序,我使用(並不時提供)彩色控制台輸出。 在重新安裝Windows之前,一切都很順利。 現在我無法獲得彩色輸出。
這是用於着色的腳本 。
我已經設法將問題縮小到或多或少,簡單的情況,但我不知道出了什么問題。
這是按預期工作的控制台提示符(字符串test
以紅色打印):
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.insert(0, r'c:\bin\SV\tea\src')
>>> from tea.console.color import cprint, Color
>>> cprint('test\n', Color.red)
test
>>>
但是當我使用相同版本的python運行以下腳本時,我得到輸出test
但不是紅色(沒有顏色,只是默認的控制台顏色):
import sys
sys.path.insert(0, r'c:\bin\SV\tea\src')
from tea.console.color import cprint, Color
cprint('test\n', Color.red)
c:\\Python27\\python.exe
)或py -2
運行腳本,但它沒有幫助。 任何想法我可以嘗試使這項工作?
編輯 :
也許它不是很清楚,但我用來着色輸出的腳本是在一個有問題的鏈接中給出的。 這里再一次: https : //bitbucket.org/alefnula/tea/src/dc14009a19d66f92463549332a321b29c71d47b8/src/tea/console/color.py?at=default
我找到了問題和解決方案。
我相信問題是x64 ctypes模塊中的錯誤。 我安裝了Python 2.7 x64並且該版本跟隨行(來自我所鏈接的腳本):
ctypes.windll.kernel32.SetConsoleTextAttribute(std_out_handle, code)
返回錯誤代碼6及描述The handle is invalid
。 經過一番調查,我推斷出問題可能是x64版本的python,所以我安裝了32位版本,一切都按預期工作。
既然這解決了我的問題,而且我沒有時間進行更深入的分析,我會把它留在這里,只是想給出某種解決問題的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.