Python – pipe function arguments to command line arguments in python

python

I have a python code (cmd.py) which accepts files as command line arguments and process using parse_args. I want to pass files from another code (files.py) to cmd.py, just like passing function arguments.
Can this be done without modifying cmd.py?

Best Answer

Yes it can be done:

cmd.py `files.py`

Then first files.py is executed and the output (Example: "file1.txt file2.txt") is the input for the cmd.py.

Example:

cat `ls`

This "cats" all the files found by ls in the working directory.

Related Question