Windows中Python的Popen既成功又失败

时间:2018-11-19 07:32:41

标签: python windows

@SpringBootApplication
@Slf4j
public class SpringBootShutdownHookApplication {

  public static void main(String[] args) {
    SpringApplication.run(SpringBootShutdownHookApplication.class, args);
  }

  @PreDestroy
  public void onExit() {
    log.info("###STOPing###");
    try {
      Thread.sleep(5 * 1000);
    } catch (InterruptedException e) {
      log.error("", e);;
    }
    log.info("###STOP FROM THE LIFECYCLE###");
  }
}

这有效-程序加载。

LYX_EXE = r'"c:\Program Files (x86)\LyX 2.3\bin\LyX2.3.exe"'
process = subprocess.Popen(LYX_EXE)

失败:我收到“ PermissionError:[WinError 5]访问被拒绝”。

我做错了什么?我需要第二种呼叫类型,因为我想使用参数。

1 个答案:

答案 0 :(得分:1)

我认为在第二种调用类型中,您必须避免引用(因为它已经在列表中,因此可执行文件和参数已经分开了):

LYX_EXE = r"c:\Program Files (x86)\LyX 2.3\bin\LyX2.3.exe"
process = subprocess.Popen([LYX_EXE])

另请参阅:https://docs.python.org/2/library/subprocess.html#converting-argument-sequence