Python Forum

Full Version: getting error "exec_proc.stdin.write(b'yes\n') IOError: [Errno 32] Broken pipe"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

We have a framework where we can run multiple python scripts using CLI. Most of the scripts requite user interaction during execution.
Now I am trying to automate that thing, so whenever I run python script then it will automatically give user input without user interaction. For that, I have written one sample code. Which is as below:-

import subprocess
import os
import sys
import time

def multi_executor():
    exec_cmd = 'python3.7 '+PATH+sys.argv[2]+' -m '+sys.argv[1]+' -i '+PATH+sys.argv[3]+' -l '+PATH+sys.argv[4]+' -d '+PATH+sys.argv[5]
    exec_proc = subprocess.Popen(exec_cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,shell=True)
    while True:
        exec_proc.poll()
        line = exec_proc.stdout.readline()
        exec_proc.stdout.flush()
        if "Enter: Yes or No:" str(line.strip()):
            exec_proc.stdin.write(b'yes\n')
            exec_proc.stdin.flush()

multi_executor()
When I execute the above script then it gives me a broken pipe error. Which is mentioned below:-
Error:
Traceback (most recent call last): File "sub_process.py", line 32, in <module> multi_executor() File "sub_process.py", line 29, in multi_executor exec_proc.stdin.write(b'yes\n') IOError: [Errno 32] Broken pipe
Here whenever my script tries to give stdin.write input at that time it gives a broken pipe.

Please let me know how to solve this issue. And is there any other way to fulfill my requirement then it would be very helpful.