2016-09-22 23 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文档主题吗? –

相关问题