I have a script that seeks to execute a program, copy a line from a text file, and paste it into the program, then execute a 2nd instance of the program and copy the 2nd line from the text file and paste it into the 2nd instance of the program (continued for x amount of instances).
Simplified:
Execute 1st instance of program > copy 1st line from text file > paste 1st line into program > press button on program > execute 2nd instance of program > copy 2nd line from text file > paste 2nd line into program...
Here is what I have:
import os
import sys
from tkinter import Tk
import pyperclip
import pyautogui
list = int(input('How many instances of program to execute? (default: 50) '))
print(list)
f = open(r"Textfile.txt")
for line in f:
strip = [line.strip() for line in f]
print(strip)
for i in xrange(len(strip)):
print(strip[i])
I tried (below) to combine executing the program and copying each line from the text file and pasting it into the instance of the program :
for i in range(list):
os.startfile(r'Program.exe')
with open("Textfile.txt") as f:
lines = f.readlines()
lines = [l for l in lines if "ROW" in l]
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append(lines)
pyperclip.paste()
pyautogui.click(820, 270)
How do I make the script copy text (line by line) from a text file and paste it into each instance of the program being executed?
Thanks!