我找到了這個話題,我發現這是一個解決方案:如何在Windows上使用Popen隱藏控制檯?
Module subprocess has no attribute 'STARTF_USESHOWWINDOW'
但是當我運行代碼的現實不同。 :/
運行我的代碼:
# Get the environment variables from OO-Python using subprocess oo_py_exec = os.path.join(oo_dir, r'program\python.exe') python_oo_script = ' ;'.join([ "-cimport os", "print(os.environ['URE_BOOTSTRAP'])", "print(os.environ['UNO_PATH'])", "print(os.environ['PATH'])", ]) subprocess.STARTF_USESHOWWINDOW info = subprocess.STARTUPINFO() info.dwFlags = subprocess.STARTF_USESHOWWINDOW info.wShowWindow = subprocess.SW_HIDE process = subprocess.Popen([oo_py_exec, python_oo_script], stdout=subprocess.PIPE, startupinfo=info) result = process.communicate()
控制檯顯示。
從鏈接運行代碼:
kwargs = {} if subprocess.mswindows: su = subprocess.STARTUPINFO() su.dwFlags |= subprocess.STARTF_USESHOWWINDOW su.wShowWindow = subprocess.SW_HIDE kwargs['startupinfo'] = su subprocess.Popen("cmd.exe", **kwargs)
控制檯還顯示!
Win XP的,PY 2.6
如果你沒有啓動一個子進程,顯示控制檯嗎? –
難道你不能編寫腳本,以便它可以直接由OO的Python運行嗎? –