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?

epi4
  • 387
  • 1
  • 2
  • 15
  • 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](https://stackoverflow.com/questions/24182482/python-read-from-stdin-with-arguments) – Jaffa Nov 26 '18 at 08:50

1 Answers1

2

Try that script

import sys

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

And run

echo "a" | python test.py

['test.py'] a
Crazy
  • 324
  • 2
  • 8