subprocess.Popen using relative paths

前端 未结 1 1697
春和景丽
春和景丽 2020-12-20 16:21

The docs for Popen mention that you can\'t specify your executable path relative to the \'change working directory\' kwarg.

If cwd is not No

1条回答
  •  醉梦人生
    2020-12-20 16:44

    Yes, this is platform dependant.

    On POSIX systems, the process is forked and in the child process a os.chdir(cwd) is executed before executing the executable.

    On Windows however, the CreateProcess() API call is used and cwd is passed in as the lpCurrentDirectory parameter. No directory change takes place, and the CreateProcess() call does not consult that parameter when looking for the lpApplicationName to execute.

    To keep your application cross-platform, you should not rely on the current working directory to be changed when looking up the executable.

    0 讨论(0)
提交回复
热议问题