X
X
xfec2016-11-09 17:10:55
linux
xfec, 2016-11-09 17:10:55

How to pass data to the executable script?

I have a python script that asks for some input when run. How can bash transfer this data to it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Myvrenik, 2016-11-09
@gim0

Through command line arguments. You can parse either manually or (preferably) with argparse .
An example of how to access the list of given arguments if you still want to parse yourself:

import sys

print(sys.argv)

I
ipc_ngs, 2016-11-09
@ipc_ngs

Call the script with input redirection <<< or <<
For example, to pass a single string:
or for multiple strings:

$ script.py <<_END_
some input string 1
some input string 2
some input string 3
_END_

Well, you can save the data in a file and redirect input from the .
See man bash for REDIRECTION, Here documents, Here strings.

A
abcd0x00, 2016-11-10
@abcd0x00

echo "abc" | script.py

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question