Add `exec` subcommand to use PIPE and REDIRECTION ?
See original GitHub issuePIPE and REDIRECTION are not working with pipenv run, because this uses pexpect.spawnpexpect.spawn.wait with non-interactive environment.
$ pipenv run python3 -c "print('foo')" | grep foo
# => not found
$ pipenv run python3 -c "print('foo')" > bar.txt
# => bar.txt is empty
If use os.exec instead of spawn, pipe and redirection are available.
diff --git a/pipenv/cli.py b/pipenv/cli.py
index 62a4165..f48b9e7 100644
--- a/pipenv/cli.py
+++ b/pipenv/cli.py
@@ -997,7 +997,8 @@ def run(command, args, no_interactive=False, three=None, python=False):
# Spawn the new process, and interact with it.
try:
- c = pexpect.spawn(which(command), list(args))
+ os.execv(which(command), [command] + list(args))
+ # c = pexpect.spawn(which(command), list(args))
except pexpect.exceptions.ExceptionPexpect:
click.echo(crayons.red('The command ({0}) was not found within the virtualenv!'.format(which(command))))
sys.exit(1)
$ python3 -m pipenv run python3 -c "print('foo')" | grep foo
foo
$ python3 -m pipenv run python3 -c "print('foo')" > bar.txt
$ cat bar.txt
foo
Can you add exec subcommand like bundler, or change run command to use os.exec ?
version
3.5.6, or current master (7b17058)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:7 (7 by maintainers)
Top Results From Across the Web
bash exec sending output to a pipe, how? - Stack Overflow
When a command contains a pipeline, each subcommand is run in a subshell ... Run this in the CLI with stdout redirected to...
Read more >Process substitution and pipe - Unix & Linux Stack Exchange
Process substitution is supported on systems that support named pipes (FIFOs) or the /dev/fd method of naming open files. It takes the form...
Read more >Five ways to use redirect operators in Bash | Enable Sysadmin
Redirect operators are a basic but essential part of working at the Bash command line. See how to safely redirect input and output...
Read more >Pipes and Redirection in Linux - Baeldung
A quick and practical overview of pipes and redirection in Linux. ... One common need when we run applications is to direct the...
Read more >How to pipe command output to other commands? - Super User
3. What do you expect ls | echo to do? why not simply run ls ? · 17. I used the simplest example...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hey everyone, sorry this hasn’t been addressed yet. We’re trying to work through tickets as time permits. I don’t see a particular reason that
pipenv runneeds to be a subprocess, and we have a whole list of tickets that pertain to problems because of this model. I’d like to see some formal verification that this approach doesn’t break anything the subprocess currently supports though.Using
os.execseems like it will help thehoncho/coverageissues we’ve had in the past too. I’ll need to investigate that further (or anyone with some spare time could verify thatpipenv run honcho/pipenv run coverage [params]works with theos.execmodel.)@kennethreitz, do you have any particular reasoning that we need to be spawning off subprocesses for
pipenv run?@kennethreitz OK, I will fix this !