{"id":607,"date":"2021-04-30T13:44:31","date_gmt":"2021-04-30T05:44:31","guid":{"rendered":"https:\/\/www.pfloat.top\/?p=607"},"modified":"2022-05-16T11:20:31","modified_gmt":"2022-05-16T03:20:31","slug":"java%e8%b0%83%e7%94%a8python%e5%86%99%e5%a5%bd%e7%9a%84%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/www.eutaboo.com\/index.php\/2021\/04\/30\/java%e8%b0%83%e7%94%a8python%e5%86%99%e5%a5%bd%e7%9a%84%e7%a8%8b%e5%ba%8f\/","title":{"rendered":"java\u8c03\u7528python\u5199\u597d\u7684\u7a0b\u5e8f"},"content":{"rendered":"<h2>\u8d77\u56e0<\/h2>\n<p>\u7531\u4e8e\u6bd5\u8bbe\u8001\u5e08\u8981\u6c42\u8981\u7528springboot\u6846\u67b6\uff0c\u4f46\u6570\u636e\u6e05\u6d17\u7528python\u5199\u66f4\u7b80\u5355\uff0c\u56e0\u6b64\u51b3\u5b9a\u5728python\u4e0a\u5199\u597d\u6570\u636e\u6e05\u6d17\u7b49\u529f\u80fd\u7684\u4ee3\u7801\uff0c\u7136\u540e\u5728java\u91cc\u9762\u76f4\u63a5\u8c03\u7528<\/p>\n<hr \/>\n<h2>java\u4ee3\u7801<\/h2>\n<pre><code class=\"language-java line-numbers\">String[] args = new String[] { python, D:\\\\pycharm_file\\\\test\\\\main.py, 2 };\nRuntime.getRuntime().exec(args);\/\/ \u6267\u884cpy\u6587\u4ef6\n\n<\/code><\/pre>\n<p>\u5176\u4e2d\uff0c\u201c2\u201d\u8868\u793a\u4f20\u7684\u53c2\u6570\uff0c\u5c31\u662fpython\u91cc\u7684sys.argv\u6570\u7ec4\u6240\u63a5\u6536\u5230\u7684\u3002<\/p>\n<hr \/>\n<h2>python\u4ee3\u7801<\/h2>\n<p>PS\uff1a\u6b64\u5904\u4ec5\u7ed9\u4e2a\u793a\u4f8b\u4ee3\u7801<\/p>\n<pre><code class=\"language-python line-numbers\">import sys\ndef a():\n    print('hello a')\ndef b():\n    print('hello b')\nif __name__ == '__main__':\n    n = int(sys.argv[1])\n    if n == 1:\n        a()\n    elif n == 2:\n        b()\n    else:\n        print('error!!out of index!')\n\n<\/code><\/pre>\n<p>\u5176\u4e2d\uff0csys.argv\u7528\u4e8e\u63a5\u6536\u4f20\u53c2\uff0cargv[0]\u662f\u6587\u4ef6\u540d\uff0c\u56e0\u6b64\u4f20\u53c2\u4ece1\u5f00\u59cb<\/p>\n<hr \/>\n<h2>\u7ed3\u679c<\/h2>\n<p>[img]https:\/\/vkceyugu.cdn.bspapp.com\/VKCEYUGU-df9040b6-66ef-461b-92a5-f74c4e71766f\/d0e731a6-4192-445a-a2d9-fab20264fbe6.png[\/img]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8d77\u56e0 \u7531\u4e8e\u6bd5\u8bbe\u8001\u5e08\u8981\u6c42\u8981\u7528springboot\u6846\u67b6\uff0c\u4f46\u6570\u636e\u6e05\u6d17\u7528python\u5199\u66f4\u7b80\u5355\uff0c\u56e0\u6b64\u51b3\u5b9a\u5728python\u4e0a\u5199\u597d\u6570\u636e\u6e05\u6d17\u7b49\u529f\u80fd\u7684 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[4],"tags":[27,36],"class_list":["post-607","post","type-post","status-publish","format-standard","hentry","category-4","tag-java","tag-python"],"views":2094,"_links":{"self":[{"href":"https:\/\/www.eutaboo.com\/index.php\/wp-json\/wp\/v2\/posts\/607","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.eutaboo.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.eutaboo.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.eutaboo.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.eutaboo.com\/index.php\/wp-json\/wp\/v2\/comments?post=607"}],"version-history":[{"count":1,"href":"https:\/\/www.eutaboo.com\/index.php\/wp-json\/wp\/v2\/posts\/607\/revisions"}],"predecessor-version":[{"id":934,"href":"https:\/\/www.eutaboo.com\/index.php\/wp-json\/wp\/v2\/posts\/607\/revisions\/934"}],"wp:attachment":[{"href":"https:\/\/www.eutaboo.com\/index.php\/wp-json\/wp\/v2\/media?parent=607"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.eutaboo.com\/index.php\/wp-json\/wp\/v2\/categories?post=607"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.eutaboo.com\/index.php\/wp-json\/wp\/v2\/tags?post=607"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}