1

I have a code that run with this command

echo "my string" | my_program.sh

and I was wondering what's the best way to do this inside a python script.

What I have for now is this

import os
my_string = "my string"
os.system('echo %s | my_program.sh' % my_string)

which seems a very dirty solution. Is there a more pythonic way of doing the same thing?

Brian
  • 13,996
  • 19
  • 70
  • 94

1 Answers1

0

Have you looked into argparse?

import argparse
parser = argparse.ArgumentParser(description='your description')
parser.add_argument('-entry', dest="entry")
args = parser.parse_args()
print (args.entry)

You can then call this with python yourfile.py -entry="this is the entry"

That will allow you to feed an input into your program.

Everyone_Else
  • 3,206
  • 4
  • 32
  • 55