2014-05-13 78 views
0

下面的代碼工作得很好。但是,一旦子進程被調用並且外部python腳本被執行,它將開始快速彈出命令提示符,因爲腳本的輸出是純文本。但是,我們已經嘗試了所有功能來禁用彈出窗口。我們嘗試添加'shell = False'和'shell = None'。我們甚至試圖編輯外部腳本本身並修改它的子進程調用,但它沒有。Python子進程造成延遲與殼

if os.path.exists(oldpath): shutil.copy(root.wgetdir + "\\" + root.website.get() + "\\" + item, keyworddir + "\\" + item) 
      shellreturn = subprocess.check_output(["C:\Python34\python",root.wgetdir + "\html2text.py", keyworddir + "\\" + item]) 
      print(shellreturn) 
      shelllist = shellreturn.decode().splitlines() 

回答

0

感謝來自@ J.F的相關文章。塞巴斯蒂安,我能弄清楚如何消除shell彈出。以下是我使用的代碼。

startupinfo = subprocess.STARTUPINFO() 
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW  
shellreturn = subprocess.check_output(["C:\Python34\python", root.wgetdir + "\html2text.py", keyworddir + "\\" + item], startupinfo=startupinfo) #this could be any subprocess. 
+1

使用'r「C:\ Python \ n \ f」'而不是'「C:\ Python \ n \ f」'。後者在其中有字面換行('「\ n」')。使用'os.path.join(keyworddir,item)'而不是'keyworddir +「\\」+ item' – jfs