0

I have a file in my directory called foo.py that contains Python code. How do I pipe the file to Python in the terminal so that Python will run it? Entering this into the terminal doesn't work:
find -name foo.py -print | python

0

1 Answer 1

1

Use -exec parameter to find and execute all the founded .py files.

find -name '*.py' -exec python {} \;

And for a single file, you may use

find -name 'foo.py' -exec python {} \;

Note that this would search for the name foo.py in the current directory as well as the subdirectories.

Sign up to request clarification or add additional context in comments.

4 Comments

And it's better to add -type f argument to the above find command.
This works, but I am wondering if there is a way to pipe it just out of curiosity, because it works if I pipe input to the script itself like so: echo <some argument> | python foo.py
But it doesn't work with piping just the script name to python
try find -name foo.py -print | xargs python

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.