-3

It is possible to make a python script which opens a cmd window and enters 5 commands one by one, and after waits for an external trigger to continue entering another 2 commands in the same window.

It is posibble? I hope You understand what I ask. PS: maybe you can share with me a sample code or something.

Thank you in advance. M.

7
  • 1
    Is it important for you that the terminal actually opens or does it suffice if you only run the commands? Commented Jul 14, 2016 at 11:39
  • You can take a look at Python's subprocess module Commented Jul 14, 2016 at 11:40
  • Its not important It can be either way, but maybe the terminal should be on in order to see the progress of the commands. Commented Jul 14, 2016 at 11:41
  • 1
    Possible duplicate of How to execute a command prompt command from python Commented Jul 14, 2016 at 11:42
  • i guess you want to see them typed in, as if somebody was typing them, right? Commented Jul 14, 2016 at 11:42

1 Answer 1

3

What i have done in the past is use Python to write a .bat file and run it. And this does produce the result you describe. You can do this like that:

import subprocess

with open(r'my_bat_file.bat','w') as fout:
    fout.write('command no1')
    fout.write('command no2')
    ...
    fout.write('command non')
    fout.write('pause')

subprocess.run(r'my_bat_file.bat', creationflags=subprocess.CREATE_NEW_CONSOLE)

The pause command keeps the cmd open and waiting for a key stroke. When the key even logs, execution of the bat file will continue. If the pause is the last line in your batch file, cmd will close.

Sign up to request clarification or add additional context in comments.

7 Comments

Yes, I know about bat file, but after 4 commands I want to wait until i command with a trigger to enter another 2 commands in the same window.
@Mihail why not add them from the beginning ? They execute sequentially any way
Because the last 2 commands are activated from an external system such a button or something.
@Mihail Adding a pause command to the shell does not help you either, does it?
This pause command it like a delay? because with delay will not work, just because I don't have a specific time for the last commands, its entirely depends on the feedback of some device.
|

Your Answer

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.