0

I need to execute my python program in the following way: echo -e arg1|myprogram.py.

In this way if I try to get the arguemnts passed to my program I get an nothing ( print(sys.arg)). How is it possible to get the arguments like that?

1
  • 2
    What you're trying to do is to read from stdin, there are plenty of questions about that, now that you know what you're looking for ;-) Possible duplicate of Python Read from Stdin with Arguments Commented Nov 26, 2018 at 8:50

1 Answer 1

2

Try that script

import sys

print(sys.argv, sys.stdin.read())

And run

echo "a" | python test.py

['test.py'] a
Sign up to request clarification or add additional context in comments.

Comments

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.