question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add `exec` subcommand to use PIPE and REDIRECTION ?

See original GitHub issue

PIPE and REDIRECTION are not working with pipenv run, because this uses pexpect.spawn pexpect.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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
nateprewittcommented, Apr 19, 2017

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 run needs 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.exec seems like it will help the honcho/coverage issues we’ve had in the past too. I’ll need to investigate that further (or anyone with some spare time could verify that pipenv run honcho/pipenv run coverage [params] works with the os.exec model.)

@kennethreitz, do you have any particular reasoning that we need to be spawning off subprocesses for pipenv run?

0reactions
nonylenecommented, Apr 19, 2017

@kennethreitz OK, I will fix this !

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found