I am trying to develop a code between two python program where I pass a command line argument for the second program to execute from the first program.
Asked
Active
Viewed 923 times
1
-
1How are you invoking the second program from the first? – ChrisGPT was on strike Feb 22 '20 at 14:46
3 Answers
0
One approach would be to call a function from the second program instead of using command-line arguments. You can do this by importing the said function.
Another approach would be to use command-line arguments as you said, with the command System or the Subprocess module.

afterm3
- 69
- 1
- 5
0
main.py
import os
os.system('python3 test.py 1 2 3')
Other program's main file
test.py
import sys
print('Number of arguments:', len(sys.argv), 'arguments.')
print('Argument List:', str(sys.argv))
Output
Number of arguments: 4 arguments.
Argument List: ['test.py', '1', '2', '3']
Run main.py which runs test.py file with arguments.

Vashdev Heerani
- 660
- 7
- 21
0
Try this in your first_program.py :
import os
os.system('python3.6 /path/to/second_program.py arg1')
These look related :
Run a Python script from another Python script, passing in arguments

Zee
- 21
- 1
- 2