편집을 완료 할 때까지 (새 터미널)에서 스폰 sudo는 과정은 대기 : 내 마지막 코드는 다음과 같이 진행됩니다파이썬 :
#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를 실행하기 전에 누락 된 패키지를 "즉시"설치합니다. 그것은 대부분 작동하지만 LaTeX의 편집기는 사용자 입력을 허용된다는 보장이 없기 때문에, 내가 그렇게에서이 작업을 수행하기 위해 새로운 터미널을 호출 할 필요가 끝 부분에서, 나는 명령을 또한
sudo tlmgr install [string of packages]
하고 실행해야 그들이 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 프로세스가 완료되었는지 확인하는 방법이 있습니까?
하지만 그런 식으로 호출 될 때 실행지고 첫 번째 명령처럼 보인다. 이것은 너에게도 일어나는가? – scarlet
사실, 그것을 고려하지 않았습니다. 나는 대답을 업데이트했다. – rumpel
매우 답답한 답변! – scarlet