• <i id='xS0GF'><tr id='xS0GF'><dt id='xS0GF'><q id='xS0GF'><span id='xS0GF'><b id='xS0GF'><form id='xS0GF'><ins id='xS0GF'></ins><ul id='xS0GF'></ul><sub id='xS0GF'></sub></form><legend id='xS0GF'></legend><bdo id='xS0GF'><pre id='xS0GF'><center id='xS0GF'></center></pre></bdo></b><th id='xS0GF'></th></span></q></dt></tr></i><div id='xS0GF'><tfoot id='xS0GF'></tfoot><dl id='xS0GF'><fieldset id='xS0GF'></fieldset></dl></div>
    1. <small id='xS0GF'></small><noframes id='xS0GF'>

      <legend id='xS0GF'><style id='xS0GF'><dir id='xS0GF'><q id='xS0GF'></q></dir></style></legend><tfoot id='xS0GF'></tfoot>

        <bdo id='xS0GF'></bdo><ul id='xS0GF'></ul>

        os.system 和子进程调用的区别

        The Difference between os.system and subprocess calls(os.system 和子进程调用的区别)
        <legend id='R6hdR'><style id='R6hdR'><dir id='R6hdR'><q id='R6hdR'></q></dir></style></legend>

          <i id='R6hdR'><tr id='R6hdR'><dt id='R6hdR'><q id='R6hdR'><span id='R6hdR'><b id='R6hdR'><form id='R6hdR'><ins id='R6hdR'></ins><ul id='R6hdR'></ul><sub id='R6hdR'></sub></form><legend id='R6hdR'></legend><bdo id='R6hdR'><pre id='R6hdR'><center id='R6hdR'></center></pre></bdo></b><th id='R6hdR'></th></span></q></dt></tr></i><div id='R6hdR'><tfoot id='R6hdR'></tfoot><dl id='R6hdR'><fieldset id='R6hdR'></fieldset></dl></div>

            <tbody id='R6hdR'></tbody>
          1. <tfoot id='R6hdR'></tfoot>

          2. <small id='R6hdR'></small><noframes id='R6hdR'>

                <bdo id='R6hdR'></bdo><ul id='R6hdR'></ul>
                1. 本文介绍了os.system 和子进程调用的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我创建了一个程序,它在本地服务器中创建 Web 架构,然后加载必要的浏览器以在 localhost 上显示 html 和 php 页面.

                  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.

                  os.system 调用会杀死 python 进程,但不会杀死其他进程——例如,httpd.exemysqld.exe

                  The os.system call kills the python process but doesn't kill the other processes -- for example, httpd.exe and mysqld.exe

                  subprocess调用杀死httpd.exemysqld.exe程序但继续运行python代码,之后没有代码执行subprocess 调用.

                  The subprocess call kills the httpd.exe and mysqld.exe programs but continues to run the python code, and no code executes after the subprocess call.

                  在 python 代码执行后,我将如何杀死或隐藏所有必要的进程?

                  How would i go about killing or hiding all necessary processes after the python code is executed?

                  这是我的代码.

                  os.makedirs(dr + x + '/admin' + '/css')
                  dobj = open(dr + x + '/admin' + '/css' + '/style.css', 'w')
                  dobj.close()
                  del dobj
                  os.makedirs(dr + x + '/admin' + '/js')
                  os.makedirs(dr + x + '/admin' + '/img')
                  ################################################################################
                  ## THE OS SYSTEM CALLS CLOSE THE APP BUT OPEN THE PROCESSES
                  ## AND THE SUBPROCESS CALLS CLOSE BOTH PROCESSES AND LEAVES THE APP OPEN
                  ## CANT WIN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                  os.makedirs(dr + x + '/admin' + '/conf')
                  #os.system(r'C:\xampp\apache\bin\httpd.exe')
                  #os.system(r'C:\xampp\mysql\bin\mysqld.exe')
                  subprocess.Popen(['C:\xampp\apache\bin\httpd.exe'], shell=True, creationflags=subprocess.SW_HIDE)
                  subprocess.Popen(['C:\xampp\mysql\bin\mysqld.exe'], shell=True, creationflags=subprocess.SW_HIDE)
                  webbrowser.open('localhost/' + x)
                  sys.exit()
                  ################################################################################
                  
                  
                  else:
                      backmaybe = raw_input('Already Exists... Try Again? (Y/N) ')
                  if backmaybe == 'y':
                      start()
                  else:
                      sys.exit()
                  

                  推荐答案

                  os.systemsubprocess.Popen的区别在于Popen实际上打开了一个pipe,os.system 开始一个subshell,很像 subprocess.call.Windows 只支持 *nix 操作系统的一些管道/外壳功能,但差异应该基本上是相同的.子shell 不允许您像管道那样与另一个进程的标准输入和输出进行通信.

                  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.

                  你可能想要的是像你一样使用子进程,然后调用 kill() 方法(来自文档) 在您的应用程序终止之前在管道对象上.这将让您决定何时终止该进程.您可能需要通过调用 pipe.communicate() 并关闭管道的文件句柄来满足进程想要执行的任何 i/o.

                  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.

                  这篇关于os.system 和子进程调用的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)

                        <tfoot id='MUZ1M'></tfoot>
                          <tbody id='MUZ1M'></tbody>

                          <legend id='MUZ1M'><style id='MUZ1M'><dir id='MUZ1M'><q id='MUZ1M'></q></dir></style></legend>

                        1. <small id='MUZ1M'></small><noframes id='MUZ1M'>

                          <i id='MUZ1M'><tr id='MUZ1M'><dt id='MUZ1M'><q id='MUZ1M'><span id='MUZ1M'><b id='MUZ1M'><form id='MUZ1M'><ins id='MUZ1M'></ins><ul id='MUZ1M'></ul><sub id='MUZ1M'></sub></form><legend id='MUZ1M'></legend><bdo id='MUZ1M'><pre id='MUZ1M'><center id='MUZ1M'></center></pre></bdo></b><th id='MUZ1M'></th></span></q></dt></tr></i><div id='MUZ1M'><tfoot id='MUZ1M'></tfoot><dl id='MUZ1M'><fieldset id='MUZ1M'></fieldset></dl></div>

                            <bdo id='MUZ1M'></bdo><ul id='MUZ1M'></ul>