Python:如何从 windows 下的 python 脚本启动一个不可见的 python 控制台?
Python: how to start an invisible python console from a python script under windows?
我需要从 windows 下的 python 脚本启动 python 控制台。
此控制台的输出必须写在文本框中。
我正在使用子进程,因为 python 控制台可以是 python 2 或 3,取决于用户的选择,所以我不能使用 code.InteractiveConsole。
现在,我从 python 开始 subprocess.Popen,stdin=PIPE,stdout 和 stderr 是两个文件子 classes,其中 write 方法打印在我的文本框上。
class output(file):
def __init__(self):
super(output,self).__init__("out","wb")
def write(self,data):
MyTextBox.Text = data
out=output()
一切顺利。
p=Popen("python -i",stdin=PIPE,stdout=out,stderr=err)
err 是另一个 class,与输出相同,但另一个文件。
好的,p 是一个子进程,但是 stdout 和 stderr 是 None。
当然,我错了,但我不明白!
也许我必须使用 4 个变量? out_write 和 out_read 用于标准输出,err_write、err_read 用于标准错误?
求助!
要隐藏命令提示符 window,传递适当的标志:
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
#si.wShowWindow = subprocess.SW_HIDE
subprocess.call('whoami', startupinfo=si)
我需要从 windows 下的 python 脚本启动 python 控制台。 此控制台的输出必须写在文本框中。 我正在使用子进程,因为 python 控制台可以是 python 2 或 3,取决于用户的选择,所以我不能使用 code.InteractiveConsole。 现在,我从 python 开始 subprocess.Popen,stdin=PIPE,stdout 和 stderr 是两个文件子 classes,其中 write 方法打印在我的文本框上。
class output(file):
def __init__(self):
super(output,self).__init__("out","wb")
def write(self,data):
MyTextBox.Text = data
out=output()
一切顺利。 p=Popen("python -i",stdin=PIPE,stdout=out,stderr=err) err 是另一个 class,与输出相同,但另一个文件。 好的,p 是一个子进程,但是 stdout 和 stderr 是 None。 当然,我错了,但我不明白! 也许我必须使用 4 个变量? out_write 和 out_read 用于标准输出,err_write、err_read 用于标准错误? 求助!
要隐藏命令提示符 window,传递适当的标志:
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
#si.wShowWindow = subprocess.SW_HIDE
subprocess.call('whoami', startupinfo=si)