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.
3 Answers 3
You can just concatenate your commands, delimited by a semicolon (;) and only call os.system once.
2 Comments
&& instead.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.
Comments
If you plan to execute this command in a remote machine, then you may consider using Paramiko. I have personally found it very useful and it lets you execute the command as root also.
subprocess.call()to run your subprocesses without usingcmdat all?