2016-09-22 41 views
0

我已經在Python 2.7中編寫了一些代碼,它將從.ini文件中讀取一個字符串,並使用sympy.preview生成LaTeX格式的字符串的.png圖像。這個想法是使用這個腳本在我輸入的時候在後臺生成圖像。問題是即使我在後臺運行腳本(使用pythonw.exe),兩個空的命令行窗口也會彈出latex.exedvipng.exe並立即關閉。這很煩人,因爲它會打斷我的打字。我希望能夠在不中斷的情況下「即時」進行。使用SymPy預覽時,可以防止Cmd對話框彈出嗎?

有沒有辦法阻止這些窗口打開?

這裏是我的最低工作例如:

from sympy import preview # for generating Latex images 
import ConfigParser   # for reading .ini files 

# read the latex commands from the .ini file: 
config = ConfigParser.RawConfigParser() 

config.read('mathPredictor.ini') 
one = config.get('Words', 'one') 

prefix = '\\Huge $' # make the Latex equations bigger 
suffix = '$' 
eqone = prefix + one + suffix 

# for generating Latex images: 
preview(eqone, viewer='file', filename='one.png', euler=False) 

的.ini文件

[Words] 
one=\alpha 

我運行Windows 8與Python 2.7.10 64位。這個問題交叉發佈在tex.SE

+0

你可以利用http://stackoverflow.com/questions/1802127/how-to-run-a-powershell-script-而不-顯示-A-窗口。 –

回答

1

我解決了我自己的問題。如果我從先前存在的cmd實例運行Python腳本,則窗口不會彈出。我的解決方案是啓動一個隱藏的cmd實例,並將路徑位置發送到隱藏的cmd窗口。這使得Python代碼能夠在latex.exedvipng.exe之間沒有惱人的彈出窗口的情況下執行。

我使用下面的函數來完成這AutoHotkey的語言:

Run, %comspec%, , max, pid2 ; runs cmd in hidden mode with instance name given by %pid% 
WinWait, ahk_pid %pid2% ; waits for instance to be active 
ControlSend, ,python mypythonscript.py`r, ahk_pid %pid2% ; send text for script execute 
+0

有趣。你有可能把它變成一個新的Stackoverflow文檔主題嗎? –