简体   繁体   中英

Script interactive mode

I execute a program in Linux shell. After that, the program starts as a console application and waits for keyboard inputs. Is it possible to give these inputs to the program using a python script? application

Consider using the subprocess module. If you only need to pass the input once (and not have any sort of logic based on the output), you can use the "input" parameter to specify what to pass in through stdin. If you need more flexibility with it (eg needing to pass things in multiple times based on the output), you can use the lower-level Popen interface, with the "communicate" method.

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