Skip to content

Commit

Permalink
Resolve application path with shutil.which
Browse files Browse the repository at this point in the history
Addresses non-intuitive behavior of `dotenv run python ...` on Windows
  • Loading branch information
Bajron committed Mar 15, 2024
1 parent a3212ff commit 2ab9bd7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/dotenv/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import shlex
import shutil
import sys
from contextlib import contextmanager
from subprocess import Popen
Expand Down Expand Up @@ -189,6 +190,11 @@ def run_command(command: List[str], env: Dict[str, str]) -> int:
cmd_env = os.environ.copy()
cmd_env.update(env)

# Resolve path in a consistent way
app = shutil.which(command[0])
if app is not None:
command = (app,) + command[1:]

p = Popen(command,
universal_newlines=True,
bufsize=0,
Expand Down

0 comments on commit 2ab9bd7

Please sign in to comment.