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

piping a file to a python script using exec_run #1637

Closed
scriptonist opened this issue Jun 10, 2017 · 6 comments
Closed

piping a file to a python script using exec_run #1637

scriptonist opened this issue Jun 10, 2017 · 6 comments

Comments

@scriptonist
Copy link

Using the docker python SDK, I'm trying to pipe output of an echo command to exec_run as follows.
container.exec_run(['echo','5','|','python','test.py'])
the test.py has following code

s = input()
print(s)

The output that is produced is :
b'5 | python test.py\n'

I'm trying to mimic the following vanila linux command
echo "5" | python myscript.py

@shin-
Copy link
Contributor

shin- commented Jun 12, 2017

Try container.exec_run(['sh', '-c', 'echo 5 | python test.py'])

@scriptonist
Copy link
Author

Thanks, @shin- This workaround works perfectly.But I used another hacky way to implement the same.
Thanks for the information.Will come handy in near future.

@mindcurv-nandaraj
Copy link

container.exec_run(['sh', '-c', 'echo 5 | python test.py']) in this command where to specify the container name?

@edthrn
Copy link

edthrn commented Jul 18, 2018

@shin- Your workaround works great, it just solved a problem I have been facing for a few hours now, so thank you.

However, I don't understand why it is needed to prefix the required command with sh -c... If you have time to explain it would be appreciated, thanks again!

EDIT
I think I found the explanation here: https://askubuntu.com/a/230482

@faheel
Copy link

faheel commented Dec 5, 2018

@mindcurv-nandaraj

client = docker.from_env()
container = client.containers.get('enter container ID here')
container.exec_run(...)

@MithunKinarullathil
Copy link

Try container.exec_run(['sh', '-c', 'echo 5 | python test.py'])

Thank you dude.

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

6 participants