Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support stdout file redirects in session.run() #218

Closed
schuderer opened this issue Jul 18, 2019 · 4 comments
Closed

Support stdout file redirects in session.run() #218

schuderer opened this issue Jul 18, 2019 · 4 comments

Comments

@schuderer
Copy link
Contributor

schuderer commented Jul 18, 2019

How would this feature be useful?
When building projects, I find myself having to use commands which generate output to stdout (such as pipenv lock -r) which I want to redirect to a file (e.g. >docs/requirements.txt). This currently is not possible with session.run(), because, as I understand it, special characters such as > are being escaped before they are run.

Describe the solution you'd like
It would be handy if session.run() would accept something like session.run("echo", "hello", ">hello.txt") or session.run("echo", "hello", ">", "hello.txt") and pass the redirect through so it gets executed when running the command.

Describe alternatives you've considered
I am using Makefiles and, for cross-platform reasons, make.bat. I also played around with task-specific shell/batch files. Having nox at hand, I am hoping I can centralize all my test-, but also more general build-related processes into one neat and tidy script, replacing non-Windows-compatible Makefiles and reducing clutter.

@theacodes
Copy link
Collaborator

Hi, we added this in #180. You can do

with open("pipenv-log.txt", "w") as out:
    session.run("pipenv", "lock", "-r", stdout=out)

@henryiii
Copy link
Collaborator

henryiii commented Jan 4, 2022

Maybe dumb question: is there a way to get the output directly in a variable, without a file? I don't seem to be get a StringIO/BytesIO to work here, or a redirect_stdout. I get io.UnsupportedOperation: fileno.

@henryiii
Copy link
Collaborator

henryiii commented Jan 4, 2022

Also, I don't think this was ever documented?

@henryiii
Copy link
Collaborator

henryiii commented Jan 4, 2022

Ahh, output is returned if this is silent. I thought I'd done this somewhere before. (Ironically, probably for something very similar to what I'm doing now, grabbing a version).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants