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.

piping a file to a python script using exec_run

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

10reactions
shin-commented, Jun 12, 2017

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

0reactions
MithunKinarullathilcommented, May 24, 2022

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

Thank you dude.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pipe output from shell command to a python script
You need to read from stdin to retrieve the data in the python script e.g. #!/usr/bin/env python import sys def hello(variable): print variable...
Read more >
The many ways to pass code to Python from the terminal
The many ways to pass code to Python from the terminal · Via stdin and piping · A string via -c · A...
Read more >
Running other programs from Tcl - exec, open
If the first character in the file name argument is a "pipe" symbol ( | ), then open will treat the rest of...
Read more >
shell_exec - Manual - PHP
shell_exec — Execute command via shell and return the complete output as a string ... Redirecting the output to a file like this...
Read more >
os/exec - Go Packages
The functions Command and LookPath look for a program in the directories listed in the ... Variables; func LookPath(file string) (string, error); type...
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