Senden an die Standardeingabe eines Programms in python3

Ich muss Dateien, main.py und child.py.

Ich versuche, eine Zeichenfolge an die Standardeingabe von @ zu sende main.py.

Dies ist mein unvollständiger Code:

main.py
from subprocess import *
import time

def main():
    program = Popen(['python.exe'. 'child.py', 'start'])
    while True: #waiting for'1' to be sent to the stdin
        if sys.stdin == '1':
            print('text)

if __name__ == '__main__':
    main()
child.py
import sys

if sys.argv[1] == 'start':
    inp = input('Do you want to send the argument?\n').lower()
    if inp == 'no':
        sys.exit()
    elif inp == 'yes':
        #Somehow send '1' to the stdin of 1.py while it is running

Ich habe keine Ahnung, wie das geht.

Ich verwende Windows 10 mit Python 3.5.1

-Vielen Dan

EDIT: Wenn ich das Argument an main.py zurücksende, kann ich das Programm nicht erneut öffnen. os.system öffnet das Programm erneut, was in meinem Fall nicht hilfreich ist.

Diese Programme sind eine kleine Demo von dem, was ich versuche zu tun. In meinem eigentlichen Programm kann ich das nicht, da die beiden Programme "miteinander kommunizieren" und immer geöffnet sein müssen.

Was ich beantworten muss, ist eine Möglichkeit, ein Argument an main.py zu senden, möglicherweise mit stdin, aber wenn ich mein Argument sende, kann das Programm nicht erneut geöffnet werden. Einige Beispiele wie os.system öffnen das Programm erneut, was nicht das ist, was ich versuche zu tun. Ich muss main.py immer geöffnet haben.

Ich habe meinen neuen aktuellen Code, der nicht funktioniert. Ein Fenster wird geöffnet und dann geschlossen.

main.py
from subprocess import Popen, PIPE, STDOUT
x = Popen(['python.exe', '2.py', 'start'], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
while x.poll() is None:
    if b'Do you want to send the argument?' in x.stdout.read():
        x.stdin.write(b'yes\n')
child.py
import sys
import time
time.sleep(1)
if 1 = 1:
    inp = input('Do you want to send the argument?\n').lower()
    if inp == 'no':
        sys.exit()
    elif inp == 'yes':
        sys.stdout.write('1')
        sys.stdout.flush()

Das ist mein Code.

Antworten auf die Frage(2)

Ihre Antwort auf die Frage