简体   繁体   中英

Can a Python script enter commands on the command line

I have an executable script, let's call it script.py. I am trying to run a series of commands within the terminal starting with

python3 ./differentscript.py console

which will allow me to type in additional commands.

However, I was wondering if this can be automated ie have my script somehow output and execute the commands?

Edit: I took a look at the links commented below; can someone provide an example of what this would look like?

@Chen Xie

If you want to call a few commands at once, you can call it like below:

subprocess.Popen('echo First&echo Second&echo Third', stdout=subprocess.PIPE, shell=True).stdout.read()

It's not a Pythonic solution, but it works.

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