{"id":208270,"date":"2025-07-08T10:20:40","date_gmt":"2025-07-08T02:20:40","guid":{"rendered":"https:\/\/server.hk\/cnblog\/208270\/"},"modified":"2025-07-08T10:20:40","modified_gmt":"2025-07-08T02:20:40","slug":"%e5%9c%a8%e5%91%bd%e4%bb%a4%e6%8f%90%e7%a4%ba%e7%ac%a6%e4%b8%8b%e6%89%a7%e8%a1%8c%e6%97%b6%e5%a6%82%e4%bd%95%e5%a4%84%e7%90%86%e5%b8%a6%e5%bc%95%e5%8f%b7%e5%92%8c%e4%b8%8d%e5%b8%a6%e5%bc%95%e5%8f%b7","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/208270\/","title":{"rendered":"\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e0b\u6267\u884c\u65f6\u5982\u4f55\u5904\u7406\u5e26\u5f15\u53f7\u548c\u4e0d\u5e26\u5f15\u53f7\u7684\u5b57\u7b26\u4e32\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e0b\u6267\u884c\u65f6\u5982\u4f55\u5904\u7406\u5e26\u5f15\u53f7\u548c\u4e0d\u5e26\u5f15\u53f7\u7684\u5b57\u7b26\u4e32\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-05-01 08:45:40<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e0b\u6267\u884c\u65f6\u5982\u4f55\u5904\u7406\u5e26\u5f15\u53f7\u548c\u4e0d\u5e26\u5f15\u53f7\u7684\u5b57\u7b26\u4e32\uff1f\u300b<\/span>\u5c06\u4f1a\u4ecb\u7ecd\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<pre>\ninput comes from an JSON request which looks like\n\n{ \n   \"inputString\" : \"\\\"C:\\\\Program Files (x86)\\\\7-Zip\\\\7z.exe\\\" x c:\\\\temp\\\\test.zip -oc:\\\\temp\\\\test\" \n}\n\npackage main\n\nimport (\n    \"fmt\"\n    \"os\/exec\"\n)\n\nfunc main() {\n    \/\/Input received will be of this format\n    var inputstring string = \"\\\"C:\\Program Files (x86)\\7-Zip\\7z.exe\\\" x c:\\temp\\firmware8.zip -oc:\\temp\\fw\"\n\n    cmd := exec.Command(\"cmd\", \"\/c\", inputstring)\n\n    out, err := cmd.Output()\n\n    fmt.Println(\"doneee\", string(out), \"err\", err)\n}\n<\/pre>\n<p>\u8f93\u51fa\uff1a<strong>&#8220;&#8216;\\&#8221;c:\\program files (x86)\\7-zip\\7z.exe\\<\/strong><\/p>\n<p> \u201c&#8217; \u672a\u88ab\u8bc6\u522b\u4e3a\u5185\u90e8\u6216\u5916\u90e8\u547d\u4ee4\uff0c\\r\\n\u4e0d\u53ef\u8fd0\u884c\u7684\u7a0b\u5e8f\u6216\u6279\u5904\u7406\u6587\u4ef6\u3002\\r\\n\u201d<\/p>\n<p><strong>&#8220;c:\\program files (x86)\\7-zip\\7z.exe&#8221;<\/strong> x c:\\temp\\test.zip -oc:\\temp\\test &#8211; \u6211\u5fc5\u987b\u8fd0\u884c\u6b64\u547d\u4ee4\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e0b\uff0c\u4f46\u5b83\u53ea\u662f\u6267\u884c\u7a81\u51fa\u663e\u793a\u7684\u90e8\u5206<\/p>\n<p>\u7531\u4e8e\u8f93\u5165\u5b57\u7b26\u4e32\u4e0d\u662f\u9759\u6001\u7684\uff08\u5b83\u6765\u81ea json\uff09\uff0c\u6240\u4ee5\u6211\u4eec\u4e0d\u80fd\u5c06\u5b83\u4eec\u62c6\u5206\u4e3a\u53c2\u6570<\/p>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<pre>var inputstring string = \"\\\"c:\\\\program files (x86)\\\\7-zip\\\\7z.exe\\\" x c:\\\\temp\\\\firmware8.zip -oc:\\\\temp\\\\fw\"\nvar buf, stderr bytes.buffer\n*proc := exec.command(\"cmd\")\nproc.sysprocattr = &amp;syscall.sysprocattr{cmdline: fmt.sprintf(`\/c \"%s\"`, inputstring)}* \/\/adding this line helped to add the cmd as single line\n\nproc.stderr = &amp;stderr\nproc.stdout = &amp;buf\nproc.start()\ntime.sleep(5 * time.second)\nfmt.println(\"doneee\", buf.string(), \"error is \", stderr.string())<\/pre>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u539f\u59cb\u5b57\u7b26\u4e32\u3002\u67e5\u770b\u3002<\/p>\n<pre>var inputstring string = `\"C:\\Program Files (x86)\\7-Zip\\7z.exe\" x c:\\temp\\test.zip -oc:\\temp\\test`\n<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e0b\u6267\u884c\u65f6\u5982\u4f55\u5904\u7406\u5e26\u5f15\u53f7\u548c\u4e0d\u5e26\u5f15\u53f7\u7684\u5b57\u7b26\u4e32\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#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-208270","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208270","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=208270"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208270\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=208270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=208270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=208270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}