简体   繁体   中英

Python - Spawn/Run a New Process Using Shell's stdin and stdout

I want to execute a non-python program from within python. The non-python program prompts the user for a password so I want stdin to be routed to that subprocess. Similarly, the subprocess has some stdout which I want to be printed to the console. When the subprocess terminates, I would like the parent python program to continue executing.

This seems so simple yet I'm having a hard time figuring out how to do it. The problem is that there are too many ways to do something very similar (os.spawn, os.exec, commands. , subprocess. , etc).

subprocess.call(whatever, stdin=sys.stdout, stdout=sys.stdin)

However, are you sure that the password comes in through stdin? Command-line passwords generally use a different facility.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM