Using Python's subprocess and Popen in one script to run another Python script which requires user interaction (by raw_input)

后端 未结 1 838
情深已故
情深已故 2021-01-05 05:48

The problem I have is as follows, and I will use simple example to illustrate it. I have written a python script that requires user interaction, specifically it uses the ra

相关标签:
1条回答
  • 2021-01-05 06:27

    You can only call communicate once. Therefore you need to pass all the input at once, i.e. child.communicate("1\n1\n"). Alternatively you can write to stdin:

    child = subprocess.Popen("./test.py", stdin=subprocess.PIPE)         
    
    child.stdin.write("1\n")                                                       
    child.stdin.write("1\n")
    
    0 讨论(0)
提交回复
热议问题