編集:私の最終的なコードは次のようになります:
#WARNING: all " in command need to be escaped: \\"
def spawnInNewTerminal(command):
#creates lock file
lock = open(lockPath, 'w')
lock.write("Currently performing task in separate terminal.")
lock.close()
#adds line to command to remove lock file
command += ";rm " + lockPath
#executes the command in a new terminal
process = subprocess.Popen (
['x-terminal-emulator', '-e', 'sh -c "{0}"'.format(command) ]
, stdout=subprocess.PIPE )
process.wait()
#doesn't let us proceed until the lock file has been removed by the bash command
while os.path.exists(lockPath):
time.sleep(0.1)
元の質問:
最終的にLuaLaTeXを実行する前に、不足しているパッケージを「オンザフライ」でインストールする単純なラッパーを作成しています。ほとんどの場合は機能しますが、最後にコマンドを実行する必要があります
sudo tlmgr install [string of packages]
さらに、LaTeX エディターがユーザー入力を許可する保証はないため、ユーザーが sudo パスワードを入力できるように、これを行うために新しい端末を呼び出す必要があります。
私はほとんどこれを理解しました:どちらか
process = subprocess.Popen(
shlex.split('''x-terminal-emulator -t \'Installing new packages\' -e \'sudo tlmgr install ''' + packagesString + '''\''''), stdout=subprocess.PIPE)
retcode = process.wait()
また
os.system('''x-terminal-emulator -t \'Installing new packages\' -e \'sudo tlmgr install ''' + packagesString + '''\'''')
唯一の問題は、生成された端末プロセスが完了するまでこの行が待機しないことです。実際、ユーザーがパスワードを入力したり、パッケージをダウンロードしたりする前に、すぐに次の行 (実際の LuaLaTeX の実行) に進みます!
私が理解していることから、これは sudo 子プロセスがすぐに終了するためです。続行する前に tlmgr プロセスが終了していることを確認する方法はありますか?