I have a Python script I wrote to be called from the command line. I am writing a GUI wrapper but do not want to change the main function. In the GUI code, I am calling the script using subprocess.run(['./executable.py', input])
but the input is not visible in executable.py
's sys.argv
list. How do I pass the input such that it would be visible to sys.argv
?
Here is a test script I have saved as test.py
(made it executable chmod +x test.py
):
#!/usr/bin/env python
# script to test using sys.argv with subprocess
import sys
print(sys.argv)
Here is what I get when calling this from the command line:
$> ./test.py input.txt
['./test.py', 'input.txt']
Here is what I get when calling this from within a python shell:
>>> import subprocess
>>> output = subprocess.run(['./test.py', 'input.txt'], shell=True, stdout=subprocess.PIPE)
>>> >>> print(output.stdout)
b"['./test.py']\n"
How do I get input.txt
to show up in sys.argv
?