0
from pathlib import Path
import subprocess
file_path = Path(r'C:\Users\86186\temp.tex')
subprocess.Popen([
    "wt", "powershell", "vim", "--servername", "name", "--remote-silent",
    file_path
])
print(file_path.read_text())

I hope to make the following program: When executed, a VIM terminal is opened on a temporary file. After making edits to the file and executing :wq in vim, the terminal closes, and the python program reads the content of the file.

Currently, everything works fine except one: The python program is not waiting for the terminal to close. I tried subprocess.check_call() but nothing improves. Is there a way I can tell the python program to halt and wait for the VIM terminal to close?

Keith
  • 42,110
  • 11
  • 57
  • 76
Xiaoyu Liu
  • 60
  • 5
  • This question is better suited for superuser.com. – Keith Aug 08 '22 at 00:30
  • 1
    I don't think this is a SuperUser question, since it's only about Python (the way `Popen` is used specifically) - but it *is* a question that's already been answered elsewhere on the site. – Grismar Aug 08 '22 at 00:39
  • I think this question is not duplicate with this question https://stackoverflow.com/questions/2837214/python-popen-command-wait-until-the-command-is-finished, I am not very familiar with Windows but `wt` process not waiting the for the created `powershell` subprocess to finish. When we run the command, Popen will return immediately even if we use `Popen.wait()`. `wt` command can be like `wt --wait command`. There is some issue https://github.com/microsoft/terminal/issues/8856 here – Veysel Olgun Aug 08 '22 at 00:51

0 Answers0