0

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.

nunoaomaia
  • 21
  • 6
  • I recently had this issue with sending passwords. See these answers: https://stackoverflow.com/a/25189727/1913726 https://stackoverflow.com/a/48337991/1913726 https://stackoverflow.com/a/49497562/1913726 – dmmfll Jul 05 '19 at 13:07
  • Thanks DMfll I've changed from Popen to spawn and now I can send the information without any problem. – nunoaomaia Jul 05 '19 at 14:26

0 Answers0