{"id":957921,"date":"2024-12-27T03:11:50","date_gmt":"2024-12-26T19:11:50","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/957921.html"},"modified":"2024-12-27T03:11:53","modified_gmt":"2024-12-26T19:11:53","slug":"python%e5%a6%82%e4%bd%95%e6%b8%ac%e8%a9%a6exe","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/957921.html","title":{"rendered":"python\u5982\u4f55\u6e2c\u8a66exe"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25101102\/bdd3f395-c0f6-4e92-b6a8-954ee19e1816.webp\" alt=\"python\u5982\u4f55\u6e2c\u8a66exe\" \/><\/p>\n<p><p> <strong>\u8981\u5728Python\u4e2d\u6d4b\u8bd5exe\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528subprocess\u6a21\u5757\u8c03\u7528exe\u6587\u4ef6\u3001\u6355\u83b7\u5176\u8f93\u51fa\u3001\u68c0\u67e5\u8fd4\u56de\u4ee3\u7801\u7b49\u3002<\/strong>subprocess\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u79cd\u7075\u6d3b\u7684\u65b9\u5f0f\u6765\u542f\u52a8\u548c\u7ba1\u7406\u5b50\u8fdb\u7a0b\uff0c\u4f7f\u5f97\u6211\u4eec\u53ef\u4ee5\u4e0eexe\u7a0b\u5e8f\u8fdb\u884c\u4ea4\u4e92\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Python\u4e2d\u6d4b\u8bd5exe\u6587\u4ef6\uff0c\u5305\u62ec\u4f7f\u7528subprocess\u6a21\u5757\u542f\u52a8exe\u3001\u6355\u83b7\u8f93\u51fa\u548c\u5904\u7406\u9519\u8bef\u7b49\u65b9\u9762\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001SUBPROCESS\u6a21\u5757\u7684\u4f7f\u7528<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0csubprocess\u6a21\u5757\u662f\u6700\u5e38\u7528\u7684\u7528\u4e8e\u8fd0\u884c\u5916\u90e8\u7a0b\u5e8f\u7684\u5de5\u5177\u3002\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u6765\u542f\u52a8\u548c\u7ba1\u7406\u5b50\u8fdb\u7a0b\u3002<\/p>\n<\/p>\n<p><p>1\u3001\u542f\u52a8EXE\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u4f7f\u7528subprocess\u6a21\u5757\u542f\u52a8exe\u6587\u4ef6\u975e\u5e38\u7b80\u5355\u3002\u53ef\u4ee5\u4f7f\u7528subprocess.run()\u6216subprocess.Popen()\u6765\u542f\u52a8exe\u6587\u4ef6\u3002subprocess.run()\u662fPython 3.5\u4e2d\u5f15\u5165\u7684\u4e00\u4e2a\u7b80\u5355\u63a5\u53e3\uff0c\u9002\u5408\u7528\u4e8e\u6267\u884c\u77ed\u547d\u4ee4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import subprocess<\/p>\n<p>result = subprocess.run([&#39;path\/to\/your\/exe&#39;, &#39;arg1&#39;, &#39;arg2&#39;], capture_output=True, text=True)<\/p>\n<p>print(result.stdout)<\/p>\n<p>print(result.stderr)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0csubprocess.run()\u542f\u52a8\u4e86\u6307\u5b9a\u8def\u5f84\u7684exe\u6587\u4ef6\uff0c\u5e76\u4f20\u9012\u4e86\u4e24\u4e2a\u53c2\u6570\u3002capture_output=True\u7528\u4e8e\u6355\u83b7\u6807\u51c6\u8f93\u51fa\u548c\u9519\u8bef\u8f93\u51fa\uff0ctext=True\u7528\u4e8e\u5c06\u8f93\u51fa\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u683c\u5f0f\u3002<\/p>\n<\/p>\n<p><p>2\u3001\u6355\u83b7\u8f93\u51fa\u548c\u8fd4\u56de\u4ee3\u7801<\/p>\n<\/p>\n<p><p>\u6355\u83b7exe\u6587\u4ef6\u7684\u8f93\u51fa\u548c\u8fd4\u56de\u4ee3\u7801\u5bf9\u4e8e\u6d4b\u8bd5\u800c\u8a00\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u8fd4\u56de\u4ee3\u7801\u901a\u5e38\u7528\u4e8e\u5224\u65adexe\u6587\u4ef6\u662f\u5426\u6210\u529f\u6267\u884c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if result.returncode == 0:<\/p>\n<p>    print(&quot;EXE executed successfully!&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;EXE execution f<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>led!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u68c0\u67e5result.returncode\uff0c\u6211\u4eec\u53ef\u4ee5\u4e86\u89e3exe\u6587\u4ef6\u662f\u5426\u6b63\u786e\u6267\u884c\u3002\u901a\u5e38\u8fd4\u56de\u4ee3\u7801\u4e3a0\u8868\u793a\u6210\u529f\uff0c\u800c\u975e\u96f6\u503c\u8868\u793a\u5931\u8d25\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u5904\u7406EXE\u6587\u4ef6\u7684\u8f93\u51fa<\/p>\n<\/p>\n<p><p>\u6d4b\u8bd5exe\u6587\u4ef6\u65f6\uff0c\u5904\u7406\u5176\u8f93\u51fa\u662f\u91cd\u8981\u7684\u4e00\u90e8\u5206\u3002\u8f93\u51fa\u53ef\u4ee5\u7528\u6765\u9a8c\u8bc1exe\u6587\u4ef6\u7684\u529f\u80fd\u662f\u5426\u7b26\u5408\u9884\u671f\u3002<\/p>\n<\/p>\n<p><p>1\u3001\u89e3\u6790\u8f93\u51fa<\/p>\n<\/p>\n<p><p>\u89e3\u6790exe\u6587\u4ef6\u7684\u8f93\u51fa\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u7406\u89e3\u5176\u6267\u884c\u7ed3\u679c\u3002\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6216\u5b57\u7b26\u4e32\u64cd\u4f5c\u6765\u89e3\u6790\u8f93\u51fa\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p>output = result.stdout<\/p>\n<p>matches = re.findall(r&#39;Result:\\s*(\\d+)&#39;, output)<\/p>\n<p>if matches:<\/p>\n<p>    print(&quot;Parsed result:&quot;, matches[0])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u4ece\u8f93\u51fa\u4e2d\u63d0\u53d6\u6570\u503c\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><p>2\u3001\u5904\u7406\u9519\u8bef\u4fe1\u606f<\/p>\n<\/p>\n<p><p>\u5904\u7406exe\u6587\u4ef6\u53ef\u80fd\u4ea7\u751f\u7684\u9519\u8bef\u4fe1\u606f\u540c\u6837\u91cd\u8981\u3002\u6355\u83b7\u9519\u8bef\u8f93\u51fa\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u8bca\u65ad\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if result.stderr:<\/p>\n<p>    print(&quot;Error occurred:&quot;, result.stderr)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u68c0\u67e5result.stderr\uff0c\u6211\u4eec\u53ef\u4ee5\u83b7\u53d6exe\u6587\u4ef6\u8fd0\u884c\u65f6\u7684\u9519\u8bef\u4fe1\u606f\uff0c\u5e76\u6839\u636e\u9700\u8981\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u7ba1\u7406EXE\u6587\u4ef6\u7684\u6267\u884c\u65f6\u95f4<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0cexe\u6587\u4ef6\u53ef\u80fd\u4f1a\u957f\u65f6\u95f4\u8fd0\u884c\u6216\u5361\u4f4f\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528subprocess\u6a21\u5757\u63d0\u4f9b\u7684timeout\u53c2\u6570\u6765\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4\u3002<\/p>\n<\/p>\n<p><p>1\u3001\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">try:<\/p>\n<p>    result = subprocess.run([&#39;path\/to\/your\/exe&#39;, &#39;arg1&#39;, &#39;arg2&#39;], capture_output=True, text=True, timeout=10)<\/p>\n<p>except subprocess.TimeoutExpired:<\/p>\n<p>    print(&quot;EXE execution timed out!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u8bbe\u7f6e\u4e86\u8d85\u65f6\u65f6\u95f4\u4e3a10\u79d2\u3002\u5982\u679cexe\u6587\u4ef6\u572810\u79d2\u5185\u672a\u5b8c\u6210\u6267\u884c\uff0c\u5219\u4f1a\u5f15\u53d1subprocess.TimeoutExpired\u5f02\u5e38\u3002<\/p>\n<\/p>\n<p><p>2\u3001\u5f02\u6b65\u6267\u884c<\/p>\n<\/p>\n<p><p>\u5982\u679cexe\u6587\u4ef6\u9700\u8981\u5f02\u6b65\u6267\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528subprocess.Popen()\u548c\u7ebf\u7a0b\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import threading<\/p>\n<p>def run_exe():<\/p>\n<p>    process = subprocess.Popen([&#39;path\/to\/your\/exe&#39;, &#39;arg1&#39;, &#39;arg2&#39;], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)<\/p>\n<p>    stdout, stderr = process.communicate()<\/p>\n<p>    print(&quot;Output:&quot;, stdout)<\/p>\n<p>    print(&quot;Error:&quot;, stderr)<\/p>\n<p>thread = threading.Thread(target=run_exe)<\/p>\n<p>thread.start()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u7ebf\u7a0b\u6765\u5f02\u6b65\u6267\u884cexe\u6587\u4ef6\uff0c\u5e76\u83b7\u53d6\u5176\u8f93\u51fa\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u8c03\u8bd5\u548c\u65e5\u5fd7\u8bb0\u5f55<\/p>\n<\/p>\n<p><p>\u8c03\u8bd5\u548c\u65e5\u5fd7\u8bb0\u5f55\u662f\u6d4b\u8bd5\u8fc7\u7a0b\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u901a\u8fc7\u8bb0\u5f55exe\u6587\u4ef6\u7684\u6267\u884c\u4fe1\u606f\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u5206\u6790\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><p>1\u3001\u8bb0\u5f55\u65e5\u5fd7<\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528Python\u7684logging\u6a21\u5757\u8bb0\u5f55exe\u6587\u4ef6\u7684\u6267\u884c\u65e5\u5fd7\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import logging<\/p>\n<p>logging.basicConfig(filename=&#39;exe_test.log&#39;, level=logging.DEBUG)<\/p>\n<p>logging.debug(&quot;Starting EXE execution.&quot;)<\/p>\n<p>logging.debug(&quot;Output: %s&quot;, result.stdout)<\/p>\n<p>logging.debug(&quot;Error: %s&quot;, result.stderr)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8bb0\u5f55\u65e5\u5fd7\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u51fa\u73b0\u95ee\u9898\u65f6\u67e5\u770b\u8be6\u7ec6\u7684\u6267\u884c\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><p>2\u3001\u8c03\u8bd5\u6280\u5de7<\/p>\n<\/p>\n<p><p>\u5728\u6d4b\u8bd5exe\u6587\u4ef6\u65f6\uff0c\u8c03\u8bd5\u6280\u5de7\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u5feb\u5730\u627e\u5230\u95ee\u9898\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u4f7f\u7528print()\u51fd\u6570<\/strong>\uff1a\u5728\u4ee3\u7801\u4e2d\u63d2\u5165print()\u8bed\u53e5\uff0c\u89c2\u5bdf\u7a0b\u5e8f\u7684\u6267\u884c\u8fc7\u7a0b\u548c\u53d8\u91cf\u7684\u503c\u3002<\/li>\n<li><strong>\u4f7f\u7528\u65ad\u70b9<\/strong>\uff1a\u5728IDE\u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u9010\u6b65\u6267\u884c\u7a0b\u5e8f\uff0c\u68c0\u67e5\u53d8\u91cf\u548c\u7a0b\u5e8f\u72b6\u6001\u3002<\/li>\n<li><strong>\u68c0\u67e5\u8def\u5f84\u548c\u53c2\u6570<\/strong>\uff1a\u786e\u4fddexe\u6587\u4ef6\u7684\u8def\u5f84\u548c\u4f20\u9012\u7684\u53c2\u6570\u6b63\u786e\u65e0\u8bef\u3002<\/li>\n<\/ul>\n<p><p>\u4e94\u3001\u7ed3\u5408\u5355\u5143\u6d4b\u8bd5\u6846\u67b6<\/p>\n<\/p>\n<p><p>\u5c06exe\u6587\u4ef6\u7684\u6d4b\u8bd5\u96c6\u6210\u5230Python\u7684\u5355\u5143\u6d4b\u8bd5\u6846\u67b6\u4e2d\uff0c\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u5316\u6d4b\u8bd5\u3002<\/p>\n<\/p>\n<p><p>1\u3001\u4f7f\u7528unittest\u6846\u67b6<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unittest<\/p>\n<p>class TestExe(unittest.TestCase):<\/p>\n<p>    def test_exe_execution(self):<\/p>\n<p>        result = subprocess.run([&#39;path\/to\/your\/exe&#39;, &#39;arg1&#39;, &#39;arg2&#39;], capture_output=True, text=True)<\/p>\n<p>        self.assertEqual(result.returncode, 0)<\/p>\n<p>        self.assertIn(&quot;Expected Output&quot;, result.stdout)<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    unittest.main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528unittest\u6846\u67b6\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6d4b\u8bd5\u7528\u4f8b\uff0c\u9a8c\u8bc1exe\u6587\u4ef6\u7684\u6267\u884c\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><p>2\u3001\u4f7f\u7528pytest\u6846\u67b6<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def test_exe_execution():<\/p>\n<p>    result = subprocess.run([&#39;path\/to\/your\/exe&#39;, &#39;arg1&#39;, &#39;arg2&#39;], capture_output=True, text=True)<\/p>\n<p>    assert result.returncode == 0<\/p>\n<p>    assert &quot;Expected Output&quot; in result.stdout<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7pytest\u6846\u67b6\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u7f16\u5199\u548c\u8fd0\u884c\u6d4b\u8bd5\u7528\u4f8b\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\u6d4b\u8bd5exe\u6587\u4ef6\u6d89\u53ca\u5230\u591a\u4e2a\u65b9\u9762\uff0c\u5305\u62ec\u542f\u52a8exe\u3001\u6355\u83b7\u8f93\u51fa\u3001\u5904\u7406\u9519\u8bef\u3001\u7ba1\u7406\u6267\u884c\u65f6\u95f4\u3001\u8c03\u8bd5\u548c\u8bb0\u5f55\u65e5\u5fd7\u7b49\u3002\u901a\u8fc7subprocess\u6a21\u5757\uff0c\u6211\u4eec\u53ef\u4ee5\u7075\u6d3b\u5730\u4e0eexe\u6587\u4ef6\u4ea4\u4e92\uff0c\u5e76\u7ed3\u5408\u5355\u5143\u6d4b\u8bd5\u6846\u67b6\u5b9e\u73b0\u81ea\u52a8\u5316\u6d4b\u8bd5\u3002\u65e0\u8bba\u662f\u89e3\u6790\u8f93\u51fa\u8fd8\u662f\u5904\u7406\u9519\u8bef\u4fe1\u606f\uff0c\u4ed4\u7ec6\u5206\u6790\u6bcf\u4e00\u4e2a\u6b65\u9aa4\u90fd\u80fd\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u9a8c\u8bc1exe\u6587\u4ef6\u7684\u529f\u80fd\u548c\u6027\u80fd\u3002\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u60a8\u80fd\u591f\u5728Python\u9879\u76ee\u4e2d\u66f4\u597d\u5730\u6d4b\u8bd5exe\u6587\u4ef6\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u5bf9\u751f\u6210\u7684exe\u6587\u4ef6\u8fdb\u884c\u6d4b\u8bd5\uff1f<\/strong><br \/>\u4f7f\u7528Python\u6d4b\u8bd5exe\u6587\u4ef6\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u7f16\u5199Python\u811a\u672c\u6765\u8c03\u7528exe\u6587\u4ef6\u5e76\u68c0\u67e5\u5176\u8fd4\u56de\u503c\u6216\u8f93\u51fa\u3002\u4f7f\u7528<code>subprocess<\/code>\u6a21\u5757\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002\u901a\u8fc7\u6355\u83b7\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u4fe1\u606f\uff0c\u60a8\u53ef\u4ee5\u9a8c\u8bc1exe\u6587\u4ef6\u7684\u884c\u4e3a\u662f\u5426\u7b26\u5408\u9884\u671f\u3002<\/p>\n<p><strong>\u6709\u6ca1\u6709\u63a8\u8350\u7684Python\u5e93\u53ef\u4ee5\u5e2e\u52a9\u6d4b\u8bd5exe\u6587\u4ef6\uff1f<\/strong><br \/>\u6709\u51e0\u4e2a\u5e93\u53ef\u4ee5\u5e2e\u52a9\u6d4b\u8bd5exe\u6587\u4ef6\uff0c\u5176\u4e2d<code>pytest<\/code>\u548c<code>unittest<\/code>\u662f\u6700\u5e38\u7528\u7684\u3002<code>pytest<\/code>\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u548c\u63d2\u4ef6\u7cfb\u7edf\uff0c\u9002\u5408\u5404\u79cd\u6d4b\u8bd5\u9700\u6c42\u3002\u800c<code>unittest<\/code>\u662fPython\u81ea\u5e26\u7684\u5355\u5143\u6d4b\u8bd5\u6846\u67b6\uff0c\u9002\u5408\u8fdb\u884c\u7ed3\u6784\u5316\u7684\u6d4b\u8bd5\u3002\u901a\u8fc7\u8fd9\u4e9b\u5e93\uff0c\u60a8\u53ef\u4ee5\u521b\u5efa\u6d4b\u8bd5\u7528\u4f8b\u6765\u9a8c\u8bc1exe\u7684\u529f\u80fd\u662f\u5426\u6b63\u5e38\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406exe\u6587\u4ef6\u4e2d\u7684\u5f02\u5e38\u6216\u9519\u8bef\uff1f<\/strong><br \/>\u5728\u6d4b\u8bd5exe\u6587\u4ef6\u65f6\uff0c\u6355\u83b7\u5f02\u5e38\u548c\u9519\u8bef\u81f3\u5173\u91cd\u8981\u3002\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u4f7f\u7528<code>try-except<\/code>\u8bed\u53e5\u6765\u5904\u7406\u53ef\u80fd\u51fa\u73b0\u7684\u5f02\u5e38\u3002\u6b64\u5916\uff0c\u901a\u8fc7\u5206\u6790exe\u6587\u4ef6\u7684\u8fd4\u56de\u7801\uff0c\u60a8\u53ef\u4ee5\u5224\u65ad\u7a0b\u5e8f\u662f\u5426\u6b63\u5e38\u9000\u51fa\u3002\u52a1\u5fc5\u8bb0\u5f55\u6240\u6709\u9519\u8bef\u4fe1\u606f\uff0c\u4ee5\u4fbf\u5728\u540e\u7eed\u8c03\u8bd5\u65f6\u53c2\u8003\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728Python\u4e2d\u6d4b\u8bd5exe\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528subprocess\u6a21\u5757\u8c03\u7528exe\u6587\u4ef6\u3001\u6355\u83b7\u5176\u8f93\u51fa\u3001\u68c0\u67e5\u8fd4\u56de\u4ee3\u7801\u7b49\u3002 [&hellip;]","protected":false},"author":3,"featured_media":957930,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/957921"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=957921"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/957921\/revisions"}],"predecessor-version":[{"id":957934,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/957921\/revisions\/957934"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/957930"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=957921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=957921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=957921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}