{"id":50767,"date":"2024-12-03T17:49:33","date_gmt":"2024-12-03T09:49:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/50767\/"},"modified":"2024-12-03T17:49:33","modified_gmt":"2024-12-03T09:49:33","slug":"python-subprocess-popen%e8%b0%83%e7%94%a8exe%e6%96%87%e4%bb%b6%e5%8d%a1%e4%bd%8f%e6%80%8e%e4%b9%88%e5%8a%9e%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/50767\/","title":{"rendered":"Python subprocess.Popen\u8c03\u7528exe\u6587\u4ef6\u5361\u4f4f\u600e\u4e48\u529e\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python subprocess.Popen\u8c03\u7528exe\u6587\u4ef6\u5361\u4f4f\u600e\u4e48\u529e\uff1f<\/h1>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241127\/17326953516746d5377f8ea.jpg\" class=\"aligncenter\" title=\"Python subprocess.Popen\u8c03\u7528exe\u6587\u4ef6\u5361\u4f4f\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" alt=\"Python subprocess.Popen\u8c03\u7528exe\u6587\u4ef6\u5361\u4f4f\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>python subprocess.popen \u8c03\u7528 exe \u6587\u4ef6\u65f6\u5361\u4f4f\u7684\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>python \u4e2d\u7684 subprocess.popen \u53ef\u4ee5\u7528\u6765\u8c03\u7528\u5916\u90e8\u7a0b\u5e8f\uff0c\u4f46\u6709\u65f6\u5728\u8c03\u7528 exe \u6587\u4ef6\u65f6\u53ef\u80fd\u4f1a\u9047\u5230\u7a0b\u5e8f\u5361\u4f4f\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u9020\u6210\u8fd9\u79cd\u95ee\u9898\u7684\u539f\u56e0\u4e4b\u4e00\u662f\u5bf9\u4e8e\u6807\u51c6\u8f93\u5165\u548c\u8f93\u51fa\u7684\u91cd\u5b9a\u5411\u9519\u8bef\u3002\u5728\u4f7f\u7528\u5217\u8868\u4f20\u9012\u53c2\u6570\u7684\u65b9\u5f0f\u8c03\u7528\u7a0b\u5e8f\u65f6\uff0c\u91cd\u5b9a\u5411\u7b26\u53f7 &lt; \u548c &gt; \u4e0d\u662f\u6709\u6548\u53c2\u6570\uff0c\u5bfc\u81f4\u7a0b\u5e8f\u65e0\u6cd5\u6b63\u786e\u4f20\u9012\u8f93\u5165\u548c\u8f93\u51fa\u3002<\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528 stdin \u548c stdout \u53c2\u6570\u6765\u660e\u786e\u6307\u5b9a\u8f93\u5165\u548c\u8f93\u51fa\u6587\u4ef6\u5bf9\u8c61\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>with open(\"...\\\\i.in\") as fpin, open(\"..\\\\1_1.out\", \"w\") as fpout:\n    subprocess.Popen([\".\/1\"], stdin=fpin, stdout=fpout)<\/pre>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0cfpin \u6307\u5411\u8f93\u5165\u6587\u4ef6\uff0cfpout \u6307\u5411\u8f93\u51fa\u6587\u4ef6\u3002\u8fd9\u6837\uff0c\u7a0b\u5e8f\u5c31\u53ef\u4ee5\u6b63\u786e\u91cd\u5b9a\u5411\u8f93\u5165\u548c\u8f93\u51fa\uff0c\u4e0d\u4f1a\u5bfc\u81f4\u8fdb\u7a0b\u5361\u4f4f\u3002<\/p>\n<p>\u53c2\u8003\u6587\u6863\uff1a<\/p>\n<ul>\n<li>python \u6587\u6863\uff1asubprocess.popen([https:\/\/docs.python.org\/3\/library\/subprocess.html#subprocess.popen])<\/li>\n<\/ul>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aPython subprocess.Popen\u8c03\u7528exe\u6587\u4ef6\u5361\u4f4f\u600e\u4e48\u529e\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python subprocess.Popen\u8c03\u7528exe\u6587\u4ef6\u5361\u4f4f\u600e\u4e48\u529e\uff1f python subprocess.popen \u8c03\u7528 exe \u6587\u4ef6\u65f6\u5361\u4f4f\u7684\u89e3\u51b3\u65b9\u6848 python \u4e2d\u7684 subprocess.popen \u53ef\u4ee5\u7528\u6765\u8c03\u7528\u5916\u90e8\u7a0b\u5e8f\uff0c\u4f46\u6709\u65f6\u5728\u8c03\u7528 exe \u6587\u4ef6\u65f6\u53ef\u80fd\u4f1a\u9047\u5230\u7a0b\u5e8f\u5361\u4f4f\u7684\u60c5\u51b5\u3002 \u9020\u6210\u8fd9\u79cd\u95ee\u9898\u7684\u539f\u56e0\u4e4b\u4e00\u662f\u5bf9\u4e8e\u6807\u51c6\u8f93\u5165\u548c\u8f93\u51fa\u7684\u91cd\u5b9a\u5411\u9519\u8bef\u3002\u5728\u4f7f\u7528\u5217\u8868\u4f20\u9012\u53c2\u6570\u7684\u65b9\u5f0f\u8c03\u7528\u7a0b\u5e8f\u65f6\uff0c\u91cd\u5b9a\u5411\u7b26\u53f7 &lt; \u548c &gt; \u4e0d\u662f\u6709\u6548\u53c2\u6570\uff0c\u5bfc\u81f4\u7a0b\u5e8f\u65e0\u6cd5\u6b63\u786e\u4f20\u9012\u8f93\u5165\u548c\u8f93\u51fa\u3002 \u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528 stdin \u548c stdout \u53c2\u6570\u6765\u660e\u786e\u6307\u5b9a\u8f93\u5165\u548c\u8f93\u51fa\u6587\u4ef6\u5bf9\u8c61\u3002\u4f8b\u5982\uff1a with open(&#8220;&#8230;\\\\i.in&#8221;) as fpin, open(&#8220;..\\\\1_1.out&#8221;, &#8220;w&#8221;) as fpout: subprocess.Popen([&#8220;.\/1&#8221;], stdin=fpin, stdout=fpout) \u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0cfpin \u6307\u5411\u8f93\u5165\u6587\u4ef6\uff0cfpout \u6307\u5411\u8f93\u51fa\u6587\u4ef6\u3002\u8fd9\u6837\uff0c\u7a0b\u5e8f\u5c31\u53ef\u4ee5\u6b63\u786e\u91cd\u5b9a\u5411\u8f93\u5165\u548c\u8f93\u51fa\uff0c\u4e0d\u4f1a\u5bfc\u81f4\u8fdb\u7a0b\u5361\u4f4f\u3002 \u53c2\u8003\u6587\u6863\uff1a python \u6587\u6863\uff1asubprocess.popen([https:\/\/docs.python.org\/3\/library\/subprocess.html#subprocess.popen]) \u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aPython subprocess.Popen\u8c03\u7528exe\u6587\u4ef6\u5361\u4f4f\u600e\u4e48\u529e\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/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-50767","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50767","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=50767"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50767\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=50767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=50767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=50767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}