-1

I am running a pogram "xxx" in the windows cmd shell. With a python script I want to check whether this specific process "xxx" is frozen or not. If so, it should reopen the process with

os.system(r'xxx.bat')

but then the python script does no check anymore because its running the process...

How can I open another, standalone CMD Terminal so that the python script starts checking again immediately after opening the shell?

Mabignix
  • 11
  • 5
  • 1
    You have only shown us code to run a batch file from python, we need more specific information, more code, debugging and what happens, if you want us to assist you with a specific problem. – Compo Sep 29 '22 at 14:53
  • https://docs.python.org/3/library/multiprocessing.html – wovano Sep 29 '22 at 15:07
  • The Python documentation of [os.system](https://docs.python.org/3/library/os.html#os.system) describes this function as deprecated since years. It should not be used anymore in new coded Python scripts. There should be used the [subprocess module](https://docs.python.org/3/library/subprocess.html) which gives the Python script writer full control over how the Windows kernel library function [CreateProcess](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw) is called by `python.exe` to run an executable on Windows from within a script. – Mofi Oct 02 '22 at 08:56
  • There can be used [os.environ](https://docs.python.org/3/library/os.html#os.environ) to get the string value of environment variable `SystemRoot` concatenated with the string `"\\System32\\cmd.exe"` to get the fully qualified file name of the oldest and least powerful script interpreter still be used on Windows to run it with a `subprocess` function with the arguments `/D` and `/C` and the batch file name with full path as the current directory can be any directory on starting `python.exe` to process your Python script and must not be the directory containing the Python script and batch file. – Mofi Oct 02 '22 at 08:59
  • But I suppose the entire batch file is not needed at all and so the Windows Command Processor is also not needed because of whatever command lines the batch file contains, the same can be done with Python code in your Python script which would solve the [XY problem](https://xyproblem.info/). So I strongly recommend to go back a step and think about what is the real task to solve and write appropriate Python code for the real task to solve or at least explain the real task in the question so that Python programming experts can help on Python code for the real task. – Mofi Oct 02 '22 at 09:03

2 Answers2

0
  1. you have to first click one your cmd...it opens next
  2. you have to click second time your cmd then it open second window ....
0

For a non-blocking solution, you should try: os.startfile(xxx.bat)

However, note that os.startfile() will run the file with the application associated to the extension of said file.

FairPluto
  • 697
  • 6
  • 28
Mabignix
  • 11
  • 5
  • Be careful using `os.startfile()`, from the doc (https://docs.python.org/3/library/os.html#os.startfile), it will open the file with the program associated with the extension of your file. You should better try something from this thread - https://stackoverflow.com/questions/1818774/executing-a-subprocess-fails . – FairPluto Oct 03 '22 at 20:07