簡體   English   中英

在后台運行多行子進程命令

[英]Run a multiline subprocess command in the background

我想在 jupyter 中將腳本作為多行命令運行。 這適用於

import subprocess
script  = ''' mkdir folder1
              rm -r folder0
              touch folder1/fileX.txt
          '''
 
subprocess.run(script , shell=True)

然而,實際上腳本中的某些行需要相當長的時間,因此,我需要整個 scipt 在后台運行。

我不確定是否有辦法,除了將腳本寫入文件並從目錄中執行文件,例如:

subprocess.run('./script &' , shell=True)

非常感謝您的想法,BR,數學

好的,我有解決方案:感謝有用的評論!

script = 'bash -c "command1; command2; command3; " &'

這適用subprocess.run() 我不知道我必須明確定義 bash shell。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM