Sending a keystroke to Python subprocess without stdin-PIPE -
i have windows commandline app prints output stdout , waits indefinitely keystroke end. use function handle it:
def run_command_on_windows(command): """ run commandline program on windows os (current) :param command: command run (string) :return: returns result of command """ p = subprocess.popen(['c:\\windows\\system32\\cmd.exe', '/c'] + command.split(), stdout=subprocess.pipe, stderr=subprocess.pipe) output, err = p.communicate() p.stdin.write('\n\n') rc = p.returncode return output.split('\r\n')
all easy if use 'stdin=subprocess.pipe' in popen, can't, since app crash instantly when redirect stdin that.
p.stdin.write('\n\n')
does not work, crashed attributeerror.
is there way solve this?
write cmd script , invoke command in there i/o redirection. try echo | ...
make command end.
you can try close stdin command can't wait keypress: ... < nul:
if doesn't work, write newline file , use ... < file
if doesn't work, have change source of program (it uses special code read keyboard) or kill p.terminate()
Comments
Post a Comment