{"id":49694,"date":"2024-12-03T17:08:36","date_gmt":"2024-12-03T09:08:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49694\/"},"modified":"2024-12-03T17:08:36","modified_gmt":"2024-12-03T09:08:36","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-python-%e4%b8%ad%e9%9d%9e%e9%98%bb%e5%a1%9e%e6%96%b9%e5%bc%8f%e6%89%a7%e8%a1%8c%e5%a4%9a%e4%b8%aa%e5%a4%96%e9%83%a8%e5%91%bd%e4%bb%a4%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49694\/","title":{"rendered":"\u5982\u4f55\u5728 Python \u4e2d\u975e\u963b\u585e\u65b9\u5f0f\u6267\u884c\u591a\u4e2a\u5916\u90e8\u547d\u4ee4\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u5728 Python \u4e2d\u975e\u963b\u585e\u65b9\u5f0f\u6267\u884c\u591a\u4e2a\u5916\u90e8\u547d\u4ee4\uff1f<\/h1>\n<p>\u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728\u6587\u7ae0\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300a\u5982\u4f55\u5728 Python \u4e2d\u975e\u963b\u585e\u65b9\u5f0f\u6267\u884c\u591a\u4e2a\u5916\u90e8\u547d\u4ee4\uff1f\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241101\/17304305886724467ccae24.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728 Python \u4e2d\u975e\u963b\u585e\u65b9\u5f0f\u6267\u884c\u591a\u4e2a\u5916\u90e8\u547d\u4ee4\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728 Python \u4e2d\u975e\u963b\u585e\u65b9\u5f0f\u6267\u884c\u591a\u4e2a\u5916\u90e8\u547d\u4ee4\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u975e\u963b\u585e\u65b9\u5f0f\u5728 python \u4e2d\u6267\u884c\u5916\u90e8\u547d\u4ee4<\/strong><\/p>\n<p>\u5728\u63a7\u5236\u53f0\u4e0b\u6267\u884c\u591a\u4e2a\u547d\u4ee4\u65f6\uff0c\u901a\u5e38\u4f1a\u4f7f\u7528\u540e\u53f0\u8fd0\u884c (&gt;) \u548c\u91cd\u5b9a\u5411 (&gt;) \u7b49\u64cd\u4f5c\u7b26\u3002python \u63d0\u4f9b\u4e86\u7c7b\u4f3c\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u4f7f\u7528 subprocess.popen \u5728\u4e00\u4e2a\u65b0\u8fdb\u7a0b\u4e2d\u6267\u884c\u547d\u4ee4\uff0c\u5e76\u63a7\u5236\u8f93\u51fa\u91cd\u5b9a\u5411\u548c\u963b\u585e\u884c\u4e3a\u3002<\/p>\n<p><strong>\u4ee3\u7801\u5b9e\u73b0<\/strong><\/p>\n<pre>import subprocess\n\n# \u542f\u52a8\u547d\u4ee4 a\nsubprocess.popen([\".\/a\", \"-a\", \"1\"], stdout=subprocess.pipe, stderr=subprocess.pipe)\n\n# \u542f\u52a8\u547d\u4ee4 b\nsubprocess.popen([\".\/b\", \"-a\", \"2\"], stdout=subprocess.pipe, stderr=subprocess.pipe)\n\n# \u542f\u52a8\u547d\u4ee4 c\nsubprocess.popen([\".\/c\", \"-a\", \"3\"], stdout=subprocess.pipe, stderr=subprocess.pipe)\n\n# \u975e\u963b\u585e\u6267\u884c<\/pre>\n<p>\u901a\u8fc7\u8bbe\u7f6e stdout \u548c stderr \u53c2\u6570\u4e3a subprocess.pipe\uff0c\u53ef\u4ee5\u6355\u83b7\u547d\u4ee4\u8f93\u51fa\u5e76\u5c06\u5176\u5173\u8054\u5230 python \u7ba1\u9053\u4e2d\u3002\u8fd9\u6837\uff0c\u4e09\u4e2a\u5b50\u8fdb\u7a0b\u5c06\u5728 python \u811a\u672c\u7684\u63a7\u5236\u4e0b\u542f\u52a8\u5e76\u8fd0\u884c\uff0c\u4f46\u4e0d\u4f1a\u963b\u585e\u811a\u672c\u6267\u884c\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<p>\u4e0e\u63a7\u5236\u53f0\u4e0b\u7684\u547d\u4ee4\u6267\u884c\u4e0d\u540c\uff0c\u4f7f\u7528 subprocess.popen \u542f\u52a8\u7684\u5b50\u8fdb\u7a0b\u5728 python \u811a\u672c\u7ed3\u675f\u540e\u4f1a\u81ea\u52a8\u7ec8\u6b62\u3002\u56e0\u6b64\uff0c\u5982\u679c\u60a8\u5e0c\u671b\u5b50\u8fdb\u7a0b\u5728 python \u811a\u672c\u7ed3\u675f\u540e\u7ee7\u7eed\u8fd0\u884c\uff0c\u9700\u8981\u5bf9\u5b50\u8fdb\u7a0b\u8fdb\u884c\u989d\u5916\u7684\u5904\u7406\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>import subprocess\n\n# \u542f\u52a8\u547d\u4ee4 A\nproc_a = subprocess.Popen([\".\/A\", \"-a\", \"1\"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n\n# \u542f\u52a8\u547d\u4ee4 B\nproc_b = subprocess.Popen([\".\/B\", \"-a\", \"2\"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n\n# \u542f\u52a8\u547d\u4ee4 C\nproc_c = subprocess.Popen([\".\/C\", \"-a\", \"3\"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n\n# \u4fdd\u6301\u5b50\u8fdb\u7a0b\u8fd0\u884c\nwhile True:\n    # \u5982\u679c\u811a\u672c\u7ed3\u675f\uff0c\u5219\u9000\u51fa\u5faa\u73af\n    if not proc_a.poll() and not proc_b.poll() and not proc_c.poll():\n        break<\/pre>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300a\u5982\u4f55\u5728 Python \u4e2d\u975e\u963b\u585e\u65b9\u5f0f\u6267\u884c\u591a\u4e2a\u5916\u90e8\u547d\u4ee4\uff1f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728 Python \u4e2d\u975e\u963b\u585e\u65b9\u5f0f\u6267\u884c\u591a\u4e2a\u5916\u90e8\u547d\u4ee4\uff1f \u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728\u6587\u7ae0\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300a\u5982\u4f55\u5728 Python \u4e2d\u975e\u963b\u585e\u65b9\u5f0f\u6267\u884c\u591a\u4e2a\u5916\u90e8\u547d\u4ee4\uff1f\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~ \u975e\u963b\u585e\u65b9\u5f0f\u5728 python \u4e2d\u6267\u884c\u5916\u90e8\u547d\u4ee4 \u5728\u63a7\u5236\u53f0\u4e0b\u6267\u884c\u591a\u4e2a\u547d\u4ee4\u65f6\uff0c\u901a\u5e38\u4f1a\u4f7f\u7528\u540e\u53f0\u8fd0\u884c (&gt;) \u548c\u91cd\u5b9a\u5411 (&gt;) \u7b49\u64cd\u4f5c\u7b26\u3002python \u63d0\u4f9b\u4e86\u7c7b\u4f3c\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u4f7f\u7528 subprocess.popen \u5728\u4e00\u4e2a\u65b0\u8fdb\u7a0b\u4e2d\u6267\u884c\u547d\u4ee4\uff0c\u5e76\u63a7\u5236\u8f93\u51fa\u91cd\u5b9a\u5411\u548c\u963b\u585e\u884c\u4e3a\u3002 \u4ee3\u7801\u5b9e\u73b0 import subprocess # \u542f\u52a8\u547d\u4ee4 a subprocess.popen([&#8220;.\/a&#8221;, &#8220;-a&#8221;, &#8220;1&#8221;], stdout=subprocess.pipe, stderr=subprocess.pipe) # \u542f\u52a8\u547d\u4ee4 b subprocess.popen([&#8220;.\/b&#8221;, &#8220;-a&#8221;, &#8220;2&#8221;], stdout=subprocess.pipe, stderr=subprocess.pipe) # \u542f\u52a8\u547d\u4ee4 c subprocess.popen([&#8220;.\/c&#8221;, &#8220;-a&#8221;, &#8220;3&#8221;], stdout=subprocess.pipe, stderr=subprocess.pipe) # \u975e\u963b\u585e\u6267\u884c \u901a\u8fc7\u8bbe\u7f6e stdout \u548c stderr \u53c2\u6570\u4e3a subprocess.pipe\uff0c\u53ef\u4ee5\u6355\u83b7\u547d\u4ee4\u8f93\u51fa\u5e76\u5c06\u5176\u5173\u8054\u5230 python \u7ba1\u9053\u4e2d\u3002\u8fd9\u6837\uff0c\u4e09\u4e2a\u5b50\u8fdb\u7a0b\u5c06\u5728 python [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-49694","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49694","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=49694"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49694\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}