The Difference between os.system and subprocess calls

后端 未结 1 433
你的背包
你的背包 2021-01-02 12:29

I have created a program that creates a web architecture in a local server then loads the necessary browser to display the html and php pages on localhost.

The

相关标签:
1条回答
  • 2021-01-02 13:26

    The difference between os.system and subprocess.Popen is that Popen actually opens a pipe, and os.system starts a subshell, much like subprocess.call. Windows only half-supports some pipe/shell features of what *nix operating systems will, but the difference should still fundamentally be the same. A subshell doesn't let you communicate with the standard input and output of another process like a pipe does.

    What you probably want is to use subprocess like you are, but then call the kill() method (from the docs) on the pipe object before your application terminates. That will let you decide when you want the process terminated. You might need to satisfy whatever i/o the process wants to do by calling pipe.communicate() and closing the pipe's file handles.

    0 讨论(0)
提交回复
热议问题