I'm trying to develop a python script that calls and executes a csh script. At this moment I can execute the csh script but I'm with some problems in write to it.
Python needs to read the stdout from csh and then in some moments put information in the stdin of csh. For example, at this moment python starts the csh script and then the csh asks for a password. I can send it to csh but after this python is giving error.
with Popen(["script_name", param1, param2], stdout=PIPE, stdin=PIPE, stderr=PIPE, bufsize=1, universal_newlines=True) as p:
for line in p.stdout:
print(line, end='')
if "password" in line:
#p.stdin.write("xpto")
stdoutMsg = p.communicate("xpto")[0]
I've tried to send the password using the p.stdin.write but the execution never ends. With the "communicate" I can send the password but when the code tries to get the response of the script it give the error:
Exception in Tkinter callback (...) for line in p.stdout: ValueError: I/O operation on closed file.
I think that "communicate" is closing the PIPE.