Skip to content

Commit

Permalink
Fixed stderr/-out/-in redirection.
Browse files Browse the repository at this point in the history
  • Loading branch information
venthur committed Oct 15, 2018
1 parent 40ed1b1 commit 1aa371a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
13 changes: 2 additions & 11 deletions dotenv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
import re
import sys
from subprocess import Popen, PIPE, STDOUT
from subprocess import Popen
import warnings
from collections import OrderedDict

Expand Down Expand Up @@ -287,19 +287,10 @@ def run_command(command, env):
cmd_env.update(env)

p = Popen(command,
stdin=PIPE,
stdout=PIPE,
stderr=STDOUT,
universal_newlines=True,
bufsize=0,
shell=False,
env=cmd_env)
try:
out, _ = p.communicate()
print(out)
except Exception:
warnings.warn('An error occured, running the command:')
out, _ = p.communicate()
warnings.warn(out)
_, _ = p.communicate()

return p.returncode
12 changes: 8 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,14 @@ def test_run(cli):
assert result == 'BAR'


def test_run_with_other_env(cli, dotenv_file):
cli.invoke(dotenv_cli, ['--file', dotenv_file, 'set', 'FOO', "BAR"])
result = cli.invoke(dotenv_cli, ['--file', dotenv_file, 'run', 'printenv', 'FOO'])
assert result.output.strip() == 'BAR'
def test_run_with_other_env(cli):
DOTENV_FILE = 'dotenv'
with cli.isolated_filesystem():
sh.cd(here)
sh.touch(DOTENV_FILE)
sh.dotenv('--file', DOTENV_FILE, 'set', 'FOO', 'BAR')
result = sh.dotenv('--file', DOTENV_FILE, 'run', 'printenv', 'FOO').strip()
assert result == 'BAR'


def test_run_without_cmd(cli):
Expand Down

0 comments on commit 1aa371a

Please sign in to comment.