Skip to content

Commit 9d85edb

Browse files
wrongontheinternetJake Owen
andauthored
fix(cli): issue with execvpe on Windows (#566)
Fix dotenv run on Windows: execvpe is bad Co-authored-by: Jake Owen <[email protected]>
1 parent 8411987 commit 9d85edb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/dotenv/cli.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
from contextlib import contextmanager
66
from typing import Any, Dict, IO, Iterator, List, Optional
77

8+
if sys.platform == 'win32':
9+
from subprocess import Popen
10+
811
try:
912
import click
1013
except ImportError:
@@ -187,4 +190,16 @@ def run_command(command: List[str], env: Dict[str, str]) -> None:
187190
cmd_env = os.environ.copy()
188191
cmd_env.update(env)
189192

190-
os.execvpe(command[0], args=command, env=cmd_env)
193+
if sys.platform == 'win32':
194+
# execvpe on Windows returns control immediately
195+
# rather than once the command has finished.
196+
p = Popen(command,
197+
universal_newlines=True,
198+
bufsize=0,
199+
shell=False,
200+
env=cmd_env)
201+
_, _ = p.communicate()
202+
203+
exit(p.returncode)
204+
else:
205+
os.execvpe(command[0], args=command, env=cmd_env)

0 commit comments

Comments
 (0)