Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we execute mutiple commands in the same command prompt launched by python script?

Tags:

python

windows

I have used os.system(command) in a for loop.

By using this, CMD opens, executes the command and close. For Second command, CMD opens again, executes tha command and close. Due to this, CMD pop-ups again and again.

Meanwhile, I am not able to do another task on system. I want to do this in a CMD so that i can minimize it and continue with other task.

like image 959
devi Avatar asked Sep 11 '26 14:09

devi


2 Answers

You can just concatenate your commands, delimited by a semicolon (;) and only call os.system once.

like image 138
Klaus Byskov Pedersen Avatar answered Sep 13 '26 07:09

Klaus Byskov Pedersen


Another approach is to write all of the command strings to a .bat or .cmd file, and then execute the resulting file with os.system.

This is more useful if the number of commands per iteration is "large-ish" and less useful if there are only a few commands per iteration.

like image 21
Eric Rahmig Avatar answered Sep 13 '26 06:09

Eric Rahmig



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!