3

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.

glglgl
91.5k13 gold badges157 silver badges230 bronze badges
asked Dec 2, 2011 at 12:10
1
  • 5
    Why not use subprocess.call() to run your subprocesses without using cmd at all? Commented Dec 2, 2011 at 12:11

3 Answers 3

2

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

answered Dec 2, 2011 at 12:13
Sign up to request clarification or add additional context in comments.

2 Comments

@danihp no, but in windows you can use && instead.
Commands are read from a excel file in every iteration so cant be concatenated. Is there any other solution?
1

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.

answered Dec 2, 2011 at 16:28

Comments

0

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.

answered Dec 3, 2011 at 5:17

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.