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

Change default shell without a config file or Context? #970

Open
evadeflow opened this issue Oct 2, 2023 · 3 comments
Open

Change default shell without a config file or Context? #970

evadeflow opened this issue Oct 2, 2023 · 3 comments

Comments

@evadeflow
Copy link

evadeflow commented Oct 2, 2023

I'm trying to do something that feels like it should be simple, but I'm struggling to figure it out. I'm using Invoke 1.7.3 as a library in an app on QNX to run some commands fed to it via MQTT. I'm using Invoke because doing:

from invoke import run

is so much easier than juggling all the subprocess stuff myself(!) But QNX doesn't have /bin/bash, so I have to pass shell='/bin/sh' to every single run() invocation, e.g.:

run("/usr/bin/launch-the-nukes.sh", shell="/bin/sh")

All I want is to configure Invoke so that I don't have to provide the shell argument to run every time. Issue #752 touches on how to do this, but I want to avoid having to push another config file to this embedded system. I've read the Configuration docs, but it seems mostly targeted at folks using the invoke runner rather than library use cases. Any hints much appreciated, thank you. (If somebody answers, I can submit a documentation patch if clarifying this use case seems worthwhile...)

@robertschweizer
Copy link

Does the env var INVOKE_RUN_SHELL=/bin/sh work for you?

@evadeflow
Copy link
Author

Does the env var INVOKE_RUN_SHELL=/bin/sh work for you?

It doesn't seem to have any effect:

$ INVOKE_RUN_SHELL=/bin/xxx-sh-xxx ipython
Python 3.8.10 (default, Nov 22 2023, 10:22:35)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.12.3 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from invoke import run

In [2]: run('sleep 1')
Out[2]: <Result cmd='sleep 1' exited=0>

In [3]: try:
   ...:     run('this will fail with an error from /bin/bash')
   ...: except Exception as e:
   ...:     print(f"Error: {e}")
   ...:
/bin/bash: this: command not found
Error: Encountered a bad command exit code!

Command: 'this will fail with an error from /bin/bash'

Exit code: 127

Stdout: already printed

Stderr: already printed



In [4]:

@robertschweizer
Copy link

For me, it works when using invoke.Context.run() in a tasks.py file, but not when using invoke.run(). So it's really something special about your library use-case.

It feels like a bug, that this env var is respected in tasks.py files, but not when using invoke.run() without a context.

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

No branches or pull requests

2 participants