{"id":204418,"date":"2025-05-29T15:00:35","date_gmt":"2025-05-29T07:00:35","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204418\/"},"modified":"2025-05-29T15:00:35","modified_gmt":"2025-05-29T07:00:35","slug":"c-%e8%b0%83%e7%94%a8-python3-%e7%a8%8b%e5%ba%8f%e6%97%b6%e5%a6%82%e4%bd%95%e6%98%be%e7%a4%ba%e7%aa%97%e5%8f%a3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204418\/","title":{"rendered":"C# \u8c03\u7528 Python3 \u7a0b\u5e8f\u65f6\u5982\u4f55\u663e\u793a\u7a97\u53e3\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>C# \u8c03\u7528 Python3 \u7a0b\u5e8f\u65f6\u5982\u4f55\u663e\u793a\u7a97\u53e3\uff1f<\/h1>\n<p>\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241107\/1730950073672c33b989ee8.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>c#\u8c03\u7528python3\u7a0b\u5e8f\u65f6\u4e0d\u663e\u793a\u7a97\u53e3<\/strong><\/p>\n<p>\u5728c#\u4e2d\u8c03\u7528python3\u811a\u672c\u65f6\uff0c\u5982\u679c\u5728process\u8bbe\u7f6e\u4e2d\u6307\u5b9a\u4e86createnowindow = true\uff0c\u5219python\u811a\u672c\u8fd0\u884c\u65f6\u5c06\u4e0d\u663e\u793a\u7a97\u53e3\u3002\u8fd9\u662f\u56e0\u4e3acreatenowindow\u9009\u9879\u6307\u5b9a\u4e86\u4e0d\u5141\u8bb8\u521b\u5efa\u65b0\u7684\u63a7\u5236\u53f0\u7a97\u53e3\u3002<\/p>\n<p>\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u5c06createnowindow\u9009\u9879\u8bbe\u7f6e\u4e3afalse\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>using System.Diagnostics;\n\nnamespace CallPython\n{\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            \/\/ \u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Process \u5bf9\u8c61\u6765\u8fd0\u884c Python \u811a\u672c\n            Process p = new Process();\n\n            \/\/ \u8bbe\u7f6e Python \u89e3\u91ca\u5668\u7684\u8def\u5f84\n            p.StartInfo.FileName = \"python.exe\";\n\n            \/\/ \u8bbe\u7f6e\u8981\u8fd0\u884c\u7684 Python \u811a\u672c\u8def\u5f84\n            p.StartInfo.Arguments = \"script.py\";\n\n            \/\/ \u5141\u8bb8\u521b\u5efa\u65b0\u7684\u63a7\u5236\u53f0\u7a97\u53e3\n            p.StartInfo.CreateNoWindow = false;\n\n            \/\/ \u8fd0\u884c Python \u811a\u672c\n            p.Start();\n\n            \/\/ \u7b49\u5f85 Python \u811a\u672c\u5b8c\u6210\n            p.WaitForExit();\n        }\n    }\n}<\/pre>\n<p>\u8fd9\u6837\uff0c\u5728\u8fd0\u884cpython\u811a\u672c\u65f6\u5c31\u4f1a\u663e\u793a\u63a7\u5236\u53f0\u7a97\u53e3\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C# \u8c03\u7528 Python3 \u7a0b\u5e8f&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204418","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204418","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204418"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204418\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}