Passing argument from one python script to another -


i've got 3 files in total : clean.txt, origin.py , pump.py

clean.txt has lines in (actually website links. eg:

www.link1.com www.link2.com www.link3.com www.link4.com 

origin.py script that's reading lines 1 one , want script send link (one @ time) pump.py

pump.py script asks me 1 input, link.

now, want make read lines clean.txt (origin.py doing task) , send them pump.py 1 @ time. loop. code origin.py :

fo = open("clean.txt", "r") nremoval = str(fo.readlines()).replace('\\n','')       lines in fo :           if __name__ =="__main__":              response = nremoval              p = subprocess.popen("pump.py", stdin = subprocess.pipe)              time.sleep(2)               p.stdin.write(bytes(response, 'ascii'))              print("injected string :", response) 

origin.py

import subprocess import time  # open file  open("clean.txt", "r") fo:       # read line line      line in fo:           # remove enter , spaces single line           line = line.strip()            # call "python pump.py"           p = subprocess.popen(["python","pump.py"], stdin=subprocess.pipe)           # or "python3 pump.py"          #p = subprocess.popen(["python3","pump.py"], stdin=subprocess.pipe)           #time.sleep(2)            # send line standard input          #p.stdin.write(bytes(line, 'ascii')) # python 3          p.stdin.write(line) # python 2           print("injected string:", line) 

pump.py

#line = input() # python 3 line = raw_input() # python 2  print("received:", line) 

Comments