-3

I run a python script test.py by using python subprocess. I want to send two strings 'John', 'Henry' as argument and read the argument values from the test.py. I want something like this

subprocess.call(['python3', 'test.py']) #add two names 'John', 'Henry' as argument

test.py

print(name1) #print John
print(name2) #print Henry

How can I do this?

user1670773
  • 967
  • 4
  • 12
  • 23
  • 1
    Have you made any attempt whatsoever? Given the information you provide, it is extremely unclear how you came up with the first line but are unable to make it work. – Mad Physicist Feb 20 '18 at 03:04

1 Answers1

0

Try this:

subprocess.call(['python3', 'test.py', 'John', 'Henry'])

and change test.py to look something like this:

import sys

print(sys.argv[1])
print(sys.argv[2])
Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
  • Hi, thanks for the answer. can I pass a big string(several thousand words) as argument. I just tried that but it gives error Argument list too long – user1670773 Feb 20 '18 at 03:22
  • "Argument list too long" is probably not an issue with python, its bash: https://stackoverflow.com/a/29802900/9348376 – Sean Breckenridge Feb 20 '18 at 03:51