7

I'm using Python 2.6 on Windows 7. I have Windows .cmd file which invokes Python to run the CherryPy Web server (version 3.1.2). I start this .cmd file by executing it at the prompt in a Windows CMD shell. When CherryPy notices that one of its dependent files has changed, it restarts. There are a couple problems that arise in this configuration on Windows, because the invocation that CherryPy uses to restart itself is

os.execv(sys.executable, args)

but you can't invoke the Python executable on the .cmd file. I've managed to bypass that problem through various Python gymnastics, and now I've got it restarting by calling (essentially)

os.execv(sys.argv[0], args)

But the restarted process is detached from the keyboard; it will catch Ctrl-C, and then I'm asked

Terminate batch job (Y/N)?

but the Y or N I type is caught not by the terminating .cmd file, but by the Windows CMD shell, and it responds

'Y' is not recognized as an internal or external command, operable program or batch file.

So how do I set things up in Windows to keep the restarted process in what I'd call "the foreground" in Unix?

Sam Bayer
  • 415
  • 3
  • 10
  • This question [link](http://stackoverflow.com/questions/7004687/os-exec-on-windows) is a simpler version of this question. An answer to that question would count as an answer to this one, but it hasn't been answered satisfactorily. – Sam Bayer Sep 06 '11 at 18:49
  • Take a look at my new comment to that question. – Piotr Dobrogost Aug 04 '13 at 14:25
  • 10 years later - any ideas how to solve this? I am [struggling with same issue](https://stackoverflow.com/q/67371606/1672565) ... – s-m-e May 12 '21 at 10:04

1 Answers1

-3

you can use subprocess.call method like this example

import subprocess

retcode = subprocess.call(["ls", "-l"])

see this link for more information about subprocess class:

subprocess — Subprocess management

Arash
  • 383
  • 4
  • 16