{"id":10006842,"date":"2022-11-09T10:32:58","date_gmt":"2022-11-09T02:32:58","guid":{"rendered":"https:\/\/ityet.com\/?p=10006842"},"modified":"2022-11-09T10:32:58","modified_gmt":"2022-11-09T02:32:58","slug":"go%e4%b8%ad%e8%b0%83%e7%94%a8%e5%a4%96%e9%83%a8%e5%91%bd%e4%bb%a4%e7%9a%84%e5%87%a0%e7%a7%8d%e5%a7%bf%e5%8a%bf","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006842","title":{"rendered":"Go\u4e2d\u8c03\u7528\u5916\u90e8\u547d\u4ee4\u7684\u51e0\u79cd\u59ff\u52bf"},"content":{"rendered":"<h2>\u5f15\u5b50<\/h2>\n<p>\u5728\u5de5\u4f5c\u4e2d\uff0c\u6211\u65f6\u4e0d\u65f6\u5730\u4f1a\u9700\u8981\u5728Go\u4e2d\u8c03\u7528\u5916\u90e8\u547d\u4ee4\u3002\u524d\u6bb5\u65f6\u95f4\u6211\u505a\u4e86\u4e00\u4e2a\u5de5\u5177\uff0c\u5728\u9489\u9489\u7fa4\u4e2d\u6dfb\u52a0\u4e86\u4e00\u4e2a\u673a\u5668\u4eba\uff0c@\u8fd9\u4e2a\u673a\u5668\u4eba\u53ef\u4ee5\u8ba9\u5b83\u6267\u884c\u4e00\u4e9b\u5199\u597d\u7684\u811a\u672c\u7a0b\u5e8f\u5b8c\u6210\u6307\u5b9a\u7684\u4efb\u52a1\u3002\u673a\u5668\u4eba\u5012\u662f\u4e0d\u96be\uff0c\u7167\u7740\u9489\u9489\u5f00\u53d1\u8005\u6587\u6863\u6dfb\u52a0\u597d\u673a\u5668\u4eba\uff0c\u7136\u540e@\u8fd9\u4e2a\u673a\u5668\u4eba\u5c31\u4f1a\u5411\u4e00\u4e2a\u4f60\u6307\u5b9a\u7684\u670d\u52a1\u5668\u53d1\u9001\u4e00\u4e2aPOST\u8bf7\u6c42\uff0c\u8bf7\u6c42\u4e2d\u4f1a\u9644\u5e26\u6587\u672c\u6d88\u606f\u3002\u6240\u4ee5\u6211\u8981\u505a\u7684\u5c31\u662f\u642d\u4e00\u4e2aWeb\u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u7528go\u539f\u751f\u7684net\/http\u5305\uff0c\u4e5f\u53ef\u4ee5\u7528gin\/fasthttp\/fiber\u8fd9\u4e9bWeb\u6846\u67b6\u3002\u6536\u5230\u8bf7\u6c42\u4e4b\u540e\uff0c\u68c0\u67e5\u9644\u5e26\u6587\u672c\u4e2d\u7684\u5173\u952e\u5b57\u53bb\u8c03\u7528\u5bf9\u5e94\u7684\u7a0b\u5e8f\uff0c\u7136\u540e\u8fd4\u56de\u7ed3\u679c\u3002<\/p>\n<p>go\u6807\u51c6\u5e93\u4e2d\u7684os\/exec\u5305\u5bf9\u8c03\u7528\u5916\u90e8\u7a0b\u5e8f\u63d0\u4f9b\u4e86\u652f\u6301\uff0c\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecdos\/exec\u7684\u4f7f\u7528\u59ff\u52bf\u3002<\/p>\n<h2>\u8fd0\u884c\u547d\u4ee4<\/h2>\n<p>Linux\u4e2d\u6709\u4e2a<code>cal<\/code>\u547d\u4ee4\uff0c\u5b83\u53ef\u4ee5\u663e\u793a\u6307\u5b9a\u5e74\u3001\u6708\u7684\u65e5\u5386\uff0c\u5982\u679c\u4e0d\u6307\u5b9a\u5e74\u3001\u6708\uff0c\u9ed8\u8ba4\u4e3a\u5f53\u524d\u65f6\u95f4\u5bf9\u5e94\u7684\u5e74\u6708\u3002\u5982\u679c\u4f7f\u7528\u7684\u662fWindows\uff0c\u63a8\u8350\u5b89\u88c5msys2\uff0c\u8fd9\u4e2a\u8f6f\u4ef6\u5305\u542b\u4e86\u7edd\u5927\u591a\u6570\u7684Linux\u5e38\u7528\u547d\u4ee4\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042773545\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042773546\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u90a3\u4e48\uff0c\u5728Go\u4ee3\u7801\u4e2d\u600e\u4e48\u8c03\u7528\u8fd9\u4e2a\u547d\u4ee4\u5462\uff1f\u5176\u5b9e\u4e5f\u5f88\u7b80\u5355\uff1a<\/p>\n<pre><code class=\"go\">func main() {\n  cmd := exec.Command(&quot;cal&quot;)\n  err := cmd.Run()\n  if err != nil {\n    log.Fatalf(&quot;cmd.Run() failed: %v\/n&quot;, err)\n  }\n}<\/code><\/pre>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u8c03\u7528<code>exec.Command<\/code>\u4f20\u5165\u547d\u4ee4\u540d\uff0c\u521b\u5efa\u4e00\u4e2a\u547d\u4ee4\u5bf9\u8c61<code>exec.Cmd<\/code>\u3002\u63a5\u7740\u8c03\u7528\u8be5\u547d\u4ee4\u5bf9\u8c61\u7684<code>Run()<\/code>\u65b9\u6cd5\u8fd0\u884c\u5b83\u3002<\/p>\n<p>\u5982\u679c\u4f60\u5b9e\u9645\u8fd0\u884c\u4e86\uff0c\u4f60\u4f1a\u53d1\u73b0\u4ec0\u4e48\u4e5f\u6ca1\u6709\u53d1\u751f\uff0c\u54c8\u54c8\u3002\u4e8b\u5b9e\u4e0a\uff0c\u4f7f\u7528os\/exec\u6267\u884c\u547d\u4ee4\uff0c\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u9ed8\u8ba4\u4f1a\u88ab\u4e22\u5f03\u3002<\/p>\n<h2>\u663e\u793a\u8f93\u51fa<\/h2>\n<p><code>exec.Cmd<\/code>\u5bf9\u8c61\u6709\u4e24\u4e2a\u5b57\u6bb5<code>Stdout<\/code>\u548c<code>Stderr<\/code>\uff0c\u7c7b\u578b\u7686\u4e3a<code>io.Writer<\/code>\u3002\u6211\u4eec\u53ef\u4ee5\u5c06\u4efb\u610f\u5b9e\u73b0\u4e86<code>io.Writer<\/code>\u63a5\u53e3\u7684\u7c7b\u578b\u5b9e\u4f8b\u8d4b\u7ed9\u8fd9\u4e24\u4e2a\u5b57\u6bb5\uff0c\u7ee7\u800c\u5b9e\u73b0\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u7684\u91cd\u5b9a\u5411\u3002<code>io.Writer<\/code>\u63a5\u53e3\u5728 Go \u6807\u51c6\u5e93\u548c\u7b2c\u4e09\u65b9\u5e93\u4e2d\u968f\u5904\u53ef\u89c1\uff0c\u4f8b\u5982<code>*os.File<\/code>\u3001<code>*bytes.Buffer<\/code>\u3001<code>net.Conn<\/code>\u3002\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u5c06\u547d\u4ee4\u7684\u8f93\u51fa\u91cd\u5b9a\u5411\u5230\u6587\u4ef6\u3001\u5185\u5b58\u7f13\u5b58\u751a\u81f3\u53d1\u9001\u5230\u7f51\u7edc\u4e2d\u3002<\/p>\n<h3>\u663e\u793a\u5230\u6807\u51c6\u8f93\u51fa<\/h3>\n<p>\u5c06<code>exec.Cmd<\/code>\u5bf9\u8c61\u7684<code>Stdout<\/code>\u548c<code>Stderr<\/code>\u8fd9\u4e24\u4e2a\u5b57\u6bb5\u90fd\u8bbe\u7f6e\u4e3a<code>os.Stdout<\/code>\uff0c\u90a3\u4e48\u8f93\u51fa\u5185\u5bb9\u90fd\u5c06\u663e\u793a\u5230\u6807\u51c6\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"go\">func main() {\n  cmd := exec.Command(&quot;cal&quot;)\n  cmd.Stdout = os.Stdout\n  cmd.Stderr = os.Stderr\n  err := cmd.Run()\n  if err != nil {\n    log.Fatalf(&quot;cmd.Run() failed: %v\/n&quot;, err)\n  }\n}<\/code><\/pre>\n<p>\u8fd0\u884c\u7a0b\u5e8f\u3002\u6211\u5728git bash\u8fd0\u884c\uff0c\u5f97\u5230\u5982\u4e0b\u7ed3\u679c\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042773547\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u8f93\u51fa\u4e86\u4e2d\u6587\uff0c\u68c0\u67e5\u4e00\u4e0b\u73af\u5883\u53d8\u91cfLANG\u7684\u503c\uff0c\u679c\u7136\u662f<code>zh_CN.UTF-8<\/code>\u3002\u5982\u679c\u60f3\u8f93\u51fa\u82f1\u6587\uff0c\u53ef\u4ee5\u5c06\u73af\u5883\u53d8\u91cfLANG\u8bbe\u7f6e\u4e3a<code>en_US.UTF-8<\/code>\uff1a<\/p>\n<pre><code class=\"bash\">$ echo $LANG\nzh_CN.UTF-8\n$ LANG=en_US.UTF-8 go run main.go<\/code><\/pre>\n<p>\u5f97\u5230\u8f93\u51fa\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042773548\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u8f93\u51fa\u5230\u6587\u4ef6<\/h3>\n<p>\u6253\u5f00\u6216\u521b\u5efa\u6587\u4ef6\uff0c\u7136\u540e\u5c06\u6587\u4ef6\u53e5\u67c4\u8d4b\u7ed9<code>exec.Cmd<\/code>\u5bf9\u8c61\u7684<code>Stdout<\/code>\u548c<code>Stderr<\/code>\u8fd9\u4e24\u4e2a\u5b57\u6bb5\u5373\u53ef\u5b9e\u73b0\u8f93\u51fa\u5230\u6587\u4ef6\u7684\u529f\u80fd\u3002<\/p>\n<pre><code class=\"go\">func main() {\n  f, err := os.OpenFile(&quot;out.txt&quot;, os.O_WRONLY|os.O_CREATE, os.ModePerm)\n  if err != nil {\n    log.Fatalf(&quot;os.OpenFile() failed: %v\/n&quot;, err)\n  }\n\n  cmd := exec.Command(&quot;cal&quot;)\n  cmd.Stdout = f\n  cmd.Stderr = f\n  err = cmd.Run()\n  if err != nil {\n    log.Fatalf(&quot;cmd.Run() failed: %v\/n&quot;, err)\n  }\n}<\/code><\/pre>\n<p><code>os.OpenFile<\/code>\u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\uff0c\u6307\u5b9a<code>os.O_CREATE<\/code>\u6807\u5fd7\u8ba9\u64cd\u4f5c\u7cfb\u7edf\u5728\u6587\u4ef6\u4e0d\u5b58\u5728\u65f6\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a\uff0c\u8fd4\u56de\u8be5\u6587\u4ef6\u5bf9\u8c61<code>*os.File<\/code>\u3002<code>*os.File<\/code>\u5b9e\u73b0\u4e86<code>io.Writer<\/code>\u63a5\u53e3\u3002<\/p>\n<p>\u8fd0\u884c\u7a0b\u5e8f\uff1a<\/p>\n<pre><code class=\"bash\">$ go run main.go\n$ cat out.txt\n    November 2022   \nSu Mo Tu We Th Fr Sa\n       1  2  3  4  5\n 6  7  8  9 10 11 12\n13 14 15 16 17 18 19\n20 21 22 23 24 25 26\n27 28 29 30<\/code><\/pre>\n<h3>\u53d1\u9001\u5230\u7f51\u7edc<\/h3>\n<p>\u73b0\u5728\u6211\u4eec\u6765\u7f16\u5199\u4e00\u4e2a\u65e5\u5386\u670d\u52a1\uff0c\u63a5\u6536\u5e74\u3001\u6708\u4fe1\u606f\uff0c\u8fd4\u56de\u8be5\u6708\u7684\u65e5\u5386\u3002<\/p>\n<pre><code class=\"go\">func cal(w http.ResponseWriter, r *http.Request) {\n  year := r.URL.Query().Get(&quot;year&quot;)\n  month := r.URL.Query().Get(&quot;month&quot;)\n\n  cmd := exec.Command(&quot;cal&quot;, month, year)\n  cmd.Stdout = w\n  cmd.Stderr = w\n\n  err := cmd.Run()\n  if err != nil {\n    log.Fatalf(&quot;cmd.Run() failed: %v\/n&quot;, err)\n  }\n}\n\nfunc main() {\n  http.HandleFunc(&quot;\/cal&quot;, cal)\n  http.ListenAndServe(&quot;:8080&quot;, nil)\n}<\/code><\/pre>\n<p>\u8fd9\u91cc\u4e3a\u4e86\u7b80\u5355\uff0c\u9519\u8bef\u5904\u7406\u90fd\u7701\u7565\u4e86\u3002\u6b63\u5e38\u60c5\u51b5\u4e0b\uff0cyear\u548cmonth\u53c2\u6570\u90fd\u9700\u8981\u505a\u5408\u6cd5\u6027\u6821\u9a8c\u3002<code>exec.Command<\/code>\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u53ef\u53d8\u53c2\u6570\u4f5c\u4e3a\u547d\u4ee4\u7684\u53c2\u6570\uff1a<\/p>\n<pre><code class=\"go\">func Command(name string, arg ...string) *Cmd<\/code><\/pre>\n<p>\u8fd0\u884c\u7a0b\u5e8f\uff0c\u4f7f\u7528\u6d4f\u89c8\u5668\u8bf7\u6c42<code>localhost:8080\/cal?year=2021&amp;month=2<\/code>\u5f97\u5230\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042773549\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u4fdd\u5b58\u5230\u5185\u5b58\u5bf9\u8c61\u4e2d<\/h3>\n<p><code>*bytes.Buffer<\/code>\u540c\u6837\u4e5f\u5b9e\u73b0\u4e86<code>io.Writer<\/code>\u63a5\u53e3\uff0c\u6545\u5982\u679c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a<code>*bytes.Buffer<\/code>\u5bf9\u8c61\uff0c\u5e76\u5c06\u5176\u8d4b\u7ed9<code>exec.Cmd<\/code>\u7684<code>Stdout<\/code>\u548c<code>Stderr<\/code>\u8fd9\u4e24\u4e2a\u5b57\u6bb5\uff0c\u90a3\u4e48\u547d\u4ee4\u6267\u884c\u4e4b\u540e\uff0c\u8be5<code>*bytes.Buffer<\/code>\u5bf9\u8c61\u4e2d\u4fdd\u5b58\u7684\u5c31\u662f\u547d\u4ee4\u7684\u8f93\u51fa\u3002<\/p>\n<pre><code class=\"go\">func main() {\n  buf := bytes.NewBuffer(nil)\n  cmd := exec.Command(&quot;cal&quot;)\n  cmd.Stdout = buf\n  cmd.Stderr = buf\n  err := cmd.Run()\n  if err != nil {\n    log.Fatalf(&quot;cmd.Run() failed: %v\/n&quot;, err)\n  }\n\n  fmt.Println(buf.String())\n}<\/code><\/pre>\n<p>\u8fd0\u884c\uff1a<\/p>\n<pre><code class=\"bash\">$ go run main.go\n    November 2022   \nSu Mo Tu We Th Fr Sa\n       1  2  3  4  5\n 6  7  8  9 10 11 12\n13 14 15 16 17 18 19\n20 21 22 23 24 25 26\n27 28 29 30<\/code><\/pre>\n<p>\u8fd0\u884c\u547d\u4ee4\uff0c\u7136\u540e\u5f97\u5230\u8f93\u51fa\u7684\u5b57\u7b26\u4e32\u6216\u5b57\u8282\u5207\u7247\u8fd9\u79cd\u6a21\u5f0f\u662f\u5982\u6b64\u7684\u666e\u904d\uff0c\u5e76\u4e14\u4f7f\u7528\u4fbf\u5229\uff0c<code>os\/exec<\/code>\u5305\u63d0\u4f9b\u4e86\u4e00\u4e2a\u4fbf\u6377\u65b9\u6cd5\uff1a<code>CombinedOutput<\/code>\u3002<\/p>\n<h3>\u8f93\u51fa\u5230\u591a\u4e2a\u76ee\u7684\u5730<\/h3>\n<p>\u6709\u65f6\uff0c\u6211\u4eec\u5e0c\u671b\u80fd\u8f93\u51fa\u5230\u6587\u4ef6\u548c\u7f51\u7edc\uff0c\u540c\u65f6\u4fdd\u5b58\u5230\u5185\u5b58\u5bf9\u8c61\u3002\u4f7f\u7528go\u63d0\u4f9b\u7684<code>io.MultiWriter<\/code>\u53ef\u4ee5\u5f88\u5bb9\u6613\u5b9e\u73b0\u8fd9\u4e2a\u9700\u6c42\u3002<code>io.MultiWriter<\/code>\u5f88\u65b9\u4fbf\u5730\u5c06\u591a\u4e2a<code>io.Writer<\/code>\u8f6c\u4e3a\u4e00\u4e2a<code>io.Writer<\/code>\u3002<\/p>\n<p>\u6211\u4eec\u7a0d\u5fae\u4fee\u6539\u4e0a\u9762\u7684web\u7a0b\u5e8f\uff1a<\/p>\n<pre><code class=\"go\">func cal(w http.ResponseWriter, r *http.Request) {\n  year := r.URL.Query().Get(&quot;year&quot;)\n  month := r.URL.Query().Get(&quot;month&quot;)\n\n  f, _ := os.OpenFile(&quot;out.txt&quot;, os.O_CREATE|os.O_WRONLY, os.ModePerm)\n  buf := bytes.NewBuffer(nil)\n  mw := io.MultiWriter(w, f, buf)\n\n  cmd := exec.Command(&quot;cal&quot;, month, year)\n  cmd.Stdout = mw\n  cmd.Stderr = mw\n\n  err := cmd.Run()\n  if err != nil {\n    log.Fatalf(&quot;cmd.Run() failed: %v\/n&quot;, err)\n  }\n\n  fmt.Println(buf.String())\n}<\/code><\/pre>\n<p>\u8c03\u7528<code>io.MultiWriter<\/code>\u5c06\u591a\u4e2a<code>io.Writer<\/code>\u6574\u5408\u6210\u4e00\u4e2a<code>io.Writer<\/code>\uff0c\u7136\u540e\u5c06cmd\u5bf9\u8c61\u7684<code>Stdout<\/code>\u548c<code>Stderr<\/code>\u90fd\u8d4b\u503c\u4e3a\u8fd9\u4e2a<code>io.Writer<\/code>\u3002\u8fd9\u6837\uff0c\u547d\u4ee4\u8fd0\u884c\u65f6\u4ea7\u51fa\u7684\u8f93\u51fa\u4f1a\u5206\u522b\u9001\u5f80<code>http.ResponseWriter<\/code>\u3001<code>*os.File<\/code>\u4ee5\u53ca<code>*bytes.Buffer<\/code>\u3002<\/p>\n<h2>\u8fd0\u884c\u547d\u4ee4\uff0c\u83b7\u53d6\u8f93\u51fa<\/h2>\n<p>\u524d\u9762\u63d0\u5230\uff0c\u6211\u4eec\u5e38\u5e38\u9700\u8981\u8fd0\u884c\u547d\u4ee4\uff0c\u8fd4\u56de\u8f93\u51fa\u3002<code>exec.Cmd<\/code>\u5bf9\u8c61\u63d0\u4f9b\u4e86\u4e00\u4e2a\u4fbf\u6377\u65b9\u6cd5\uff1a<code>CombinedOutput()<\/code>\u3002\u8be5\u65b9\u6cd5\u8fd0\u884c\u547d\u4ee4\uff0c\u5c06\u8f93\u51fa\u5185\u5bb9\u4ee5\u4e00\u4e2a\u5b57\u8282\u5207\u7247\u8fd4\u56de\u4fbf\u4e8e\u540e\u7eed\u5904\u7406\u3002\u6240\u4ee5\uff0c\u4e0a\u9762\u83b7\u53d6\u8f93\u51fa\u7684\u7a0b\u5e8f\u53ef\u4ee5\u7b80\u5316\u4e3a\uff1a<\/p>\n<pre><code class=\"go\">func main() {\n  cmd := exec.Command(&quot;cal&quot;)\n  output, err := cmd.CombinedOutput()\n  if err != nil {\n    log.Fatalf(&quot;cmd.Run() failed: %v\/n&quot;, err)\n  }\n\n  fmt.Println(string(output))\n}<\/code><\/pre>\n<p>So easy!<\/p>\n<p><code>CombinedOutput()<\/code>\u65b9\u6cd5\u7684\u5b9e\u73b0\u5f88\u7b80\u5355\uff0c\u5148\u5c06\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u91cd\u5b9a\u5411\u5230<code>*bytes.Buffer<\/code>\u5bf9\u8c61\uff0c\u7136\u540e\u8fd0\u884c\u7a0b\u5e8f\uff0c\u6700\u540e\u8fd4\u56de\u8be5\u5bf9\u8c61\u4e2d\u7684\u5b57\u8282\u5207\u7247\uff1a<\/p>\n<pre><code class=\"go\">func (c *Cmd) CombinedOutput() ([]byte, error) {\n  if c.Stdout != nil {\n    return nil, errors.New(&quot;exec: Stdout already set&quot;)\n  }\n  if c.Stderr != nil {\n    return nil, errors.New(&quot;exec: Stderr already set&quot;)\n  }\n  var b bytes.Buffer\n  c.Stdout = &amp;b\n  c.Stderr = &amp;b\n  err := c.Run()\n  return b.Bytes(), err\n}<\/code><\/pre>\n<p><code>CombinedOutput<\/code>\u65b9\u6cd5\u524d\u51e0\u884c\u5224\u65ad\u8868\u660e\uff0c<code>Stdout<\/code>\u548c<code>Stderr<\/code>\u5fc5\u987b\u662f\u672a\u8bbe\u7f6e\u72b6\u6001\u3002\u8fd9\u5176\u5b9e\u5f88\u597d\u7406\u89e3\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u5df2\u7ecf\u6253\u7b97\u4f7f\u7528<code>CombinedOutput<\/code>\u65b9\u6cd5\u83b7\u53d6\u8f93\u51fa\u5185\u5bb9\uff0c\u4e0d\u4f1a\u518d\u81ea\u627e\u9ebb\u70e6\u5730\u518d\u53bb\u8bbe\u7f6e<code>Stdout<\/code>\u548c<code>Stderr<\/code>\u5b57\u6bb5\u4e86\u3002<\/p>\n<p>\u4e0e<code>CombinedOutput<\/code>\u7c7b\u4f3c\u7684\u8fd8\u6709<code>Output<\/code>\u65b9\u6cd5\uff0c\u533a\u522b\u662f<code>Output<\/code>\u53ea\u4f1a\u8fd4\u56de\u8fd0\u884c\u547d\u4ee4\u4ea7\u51fa\u7684\u6807\u51c6\u8f93\u51fa\u5185\u5bb9\u3002<\/p>\n<h2>\u5206\u522b\u83b7\u53d6\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef<\/h2>\n<p>\u521b\u5efa\u4e24\u4e2a<code>*bytes.Buffer<\/code>\u5bf9\u8c61\uff0c\u5206\u522b\u8d4b\u7ed9<code>exec.Cmd<\/code>\u5bf9\u8c61\u7684<code>Stdout<\/code>\u548c<code>Stderr<\/code>\u8fd9\u4e24\u4e2a\u5b57\u6bb5\uff0c\u7136\u540e\u8fd0\u884c\u547d\u4ee4\u5373\u53ef\u5206\u522b\u83b7\u53d6\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u3002<\/p>\n<pre><code class=\"go\">func main() {\n  cmd := exec.Command(&quot;cal&quot;, &quot;15&quot;, &quot;2012&quot;)\n  var stdout, stderr bytes.Buffer\n  cmd.Stdout = &amp;stdout\n  cmd.Stderr = &amp;stderr\n  err := cmd.Run()\n  if err != nil {\n    log.Fatalf(&quot;cmd.Run() failed: %v\/n&quot;, err)\n  }\n\n  fmt.Printf(&quot;output:\/n%s\/nerror:\/n%s\/n&quot;, stdout.String(), stderr.String())\n}<\/code><\/pre>\n<h2>\u6807\u51c6\u8f93\u5165<\/h2>\n<p><code>exec.Cmd<\/code>\u5bf9\u8c61\u6709\u4e00\u4e2a\u7c7b\u578b\u4e3a<code>io.Reader<\/code>\u7684\u5b57\u6bb5<code>Stdin<\/code>\u3002\u547d\u4ee4\u8fd0\u884c\u65f6\u4f1a\u4ece\u8fd9\u4e2a<code>io.Reader<\/code>\u8bfb\u53d6\u8f93\u5165\u3002\u5148\u6765\u770b\u4e00\u4e2a\u6700\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n<pre><code class=\"go\">func main() {\n  cmd := exec.Command(&quot;cat&quot;)\n  cmd.Stdin = bytes.NewBufferString(&quot;hello\/nworld&quot;)\n  cmd.Stdout = os.Stdout\n  err := cmd.Run()\n  if err != nil {\n    log.Fatalf(&quot;cmd.Run() failed: %v\/n&quot;, err)\n  }\n}<\/code><\/pre>\n<p>\u5982\u679c\u4e0d\u5e26\u53c2\u6570\u8fd0\u884c<code>cat<\/code>\u547d\u4ee4\uff0c\u5219\u8fdb\u5165\u4ea4\u4e92\u6a21\u5f0f\uff0c<code>cat<\/code>\u6309\u884c\u8bfb\u53d6\u8f93\u5165\uff0c\u5e76\u4e14\u539f\u6837\u53d1\u9001\u5230\u8f93\u51fa\u3002<\/p>\n<p>\u518d\u6765\u770b\u4e00\u4e2a\u590d\u6742\u70b9\u7684\u4f8b\u5b50\u3002Go\u6807\u51c6\u5e93\u4e2d<code>compress\/bzip2<\/code>\u5305\u53ea\u63d0\u4f9b\u89e3\u538b\u65b9\u6cd5\uff0c\u5e76\u6ca1\u6709\u538b\u7f29\u65b9\u6cd5\u3002\u6211\u4eec\u53ef\u4ee5\u5229\u7528Linux\u547d\u4ee4<code>bzip2<\/code>\u5b9e\u73b0\u538b\u7f29\u3002<code>bzip2<\/code>\u4ece\u6807\u51c6\u8f93\u5165\u4e2d\u8bfb\u53d6\u6570\u636e\uff0c\u5c06\u5176\u538b\u7f29\uff0c\u5e76\u53d1\u9001\u5230\u6807\u51c6\u8f93\u51fa\u3002<\/p>\n<pre><code class=\"go\">func bzipCompress(d []byte) ([]byte, error) {\n  var out bytes.Buffer\n  cmd := exec.Command(&quot;bzip2&quot;, &quot;-c&quot;, &quot;-9&quot;)\n  cmd.Stdin = bytes.NewBuffer(d)\n  cmd.Stdout = &amp;out\n  err := cmd.Run()\n  if err != nil {\n    log.Fatalf(&quot;cmd.Run() failed: %v\/n&quot;, err)\n  }\n\n  return out.Bytes(), nil\n}<\/code><\/pre>\n<p>\u53c2\u6570<code>-c<\/code>\u8868\u793a\u538b\u7f29\uff0c<code>-9<\/code>\u8868\u793a\u538b\u7f29\u7b49\u7ea7\uff0c9\u4e3a\u6700\u9ad8\u3002\u4e3a\u4e86\u9a8c\u8bc1\u51fd\u6570\u7684\u6b63\u786e\u6027\uff0c\u5199\u4e2a\u7b80\u5355\u7684\u7a0b\u5e8f\uff0c\u5148\u538b\u7f29&#8221;hello world&#8221;\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u89e3\u538b\uff0c\u770b\u770b\u662f\u5426\u80fd\u5f97\u5230\u539f\u6765\u7684\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre><code class=\"go\">func main() {\n  data := []byte(&quot;hello world&quot;)\n  compressed, _ := bzipCompress(data)\n  r := bzip2.NewReader(bytes.NewBuffer(compressed))\n  decompressed, _ := ioutil.ReadAll(r)\n  fmt.Println(string(decompressed))\n}<\/code><\/pre>\n<p>\u8fd0\u884c\u7a0b\u5e8f\uff0c\u8f93\u51fa&#8221;hello world&#8221;\u3002<\/p>\n<h2>\u73af\u5883\u53d8\u91cf<\/h2>\n<p>\u73af\u5883\u53d8\u91cf\u53ef\u4ee5\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u5fae\u8c03\u7a0b\u5e8f\u7684\u884c\u4e3a\uff0c\u5f53\u7136\u8fd9\u9700\u8981\u7a0b\u5e8f\u7684\u652f\u6301\u3002\u4f8b\u5982\uff0c\u8bbe\u7f6e<code>ENV=production<\/code>\u4f1a\u6291\u5236\u8c03\u8bd5\u65e5\u5fd7\u7684\u8f93\u51fa\u3002\u6bcf\u4e2a\u73af\u5883\u53d8\u91cf\u90fd\u662f\u4e00\u4e2a\u952e\u503c\u5bf9\u3002<code>exec.Cmd<\/code>\u5bf9\u8c61\u4e2d\u6709\u4e00\u4e2a\u7c7b\u578b\u4e3a<code>[]string<\/code>\u7684\u5b57\u6bb5<code>Env<\/code>\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u5b83\u6765\u8fbe\u5230\u63a7\u5236\u547d\u4ee4\u8fd0\u884c\u65f6\u7684\u73af\u5883\u53d8\u91cf\u7684\u76ee\u7684\u3002<\/p>\n<pre><code class=\"go\">package main\n\nimport (\n  &quot;fmt&quot;\n  &quot;log&quot;\n  &quot;os&quot;\n  &quot;os\/exec&quot;\n)\n\nfunc main() {\n  cmd := exec.Command(&quot;bash&quot;, &quot;-c&quot;, &quot;.\/test.sh&quot;)\n\n  nameEnv := &quot;NAME=darjun&quot;\n  ageEnv := &quot;AGE=18&quot;\n\n  newEnv := append(os.Environ(), nameEnv, ageEnv)\n  cmd.Env = newEnv\n\n  out, err := cmd.CombinedOutput()\n  if err != nil {\n    log.Fatalf(&quot;cmd.Run() failed: %v\/n&quot;, err)\n  }\n\n  fmt.Println(string(out))\n}<\/code><\/pre>\n<p>\u4e0a\u9762\u4ee3\u7801\u83b7\u53d6\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\uff0c\u7136\u540e\u53c8\u6dfb\u52a0\u4e86\u4e24\u4e2a\u73af\u5883\u53d8\u91cf<code>NAME<\/code>\u548c<code>AGE<\/code>\u3002\u6700\u540e\u4f7f\u7528<code>bash<\/code>\u8fd0\u884c\u811a\u672c<code>test.sh<\/code>\uff1a<\/p>\n<pre><code class=\"shell\">#!\/bin\/bash\n\necho $NAME\necho $AGE\necho $GOPATH<\/code><\/pre>\n<p>\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<pre><code class=\"bash\">$ go run main.go \ndarjun\n18\nD:\/workspace\/code\/go<\/code><\/pre>\n<h2>\u68c0\u67e5\u547d\u4ee4\u662f\u5426\u5b58\u5728<\/h2>\n<p>\u4e00\u822c\u5728\u8fd0\u884c\u547d\u4ee4\u4e4b\u524d\uff0c\u6211\u4eec\u901a\u8fc7\u5e0c\u671b\u80fd\u68c0\u67e5\u8981\u8fd0\u884c\u7684\u547d\u4ee4\u662f\u5426\u5b58\u5728\uff0c\u5982\u679c\u5b58\u5728\u5219\u76f4\u63a5\u8fd0\u884c\uff0c\u5426\u5219\u63d0\u793a\u7528\u6237\u5b89\u88c5\u6b64\u547d\u4ee4\u3002<code>os\/exec<\/code>\u5305\u63d0\u4f9b\u4e86\u51fd\u6570<code>LookPath<\/code>\u53ef\u4ee5\u83b7\u53d6\u547d\u4ee4\u6240\u5728\u76ee\u5f55\uff0c\u5982\u679c\u547d\u4ee4\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u4e00\u4e2aerror\u3002<\/p>\n<pre><code class=\"go\">func main() {\n  path, err := exec.LookPath(&quot;ls&quot;)\n  if err != nil {\n    fmt.Printf(&quot;no cmd ls: %v\/n&quot;, err)\n  } else {\n    fmt.Printf(&quot;find ls in path:%s\/n&quot;, path)\n  }\n\n  path, err = exec.LookPath(&quot;not-exist&quot;)\n  if err != nil {\n    fmt.Printf(&quot;no cmd not-exist: %v\/n&quot;, err)\n  } else {\n    fmt.Printf(&quot;find not-exist in path:%s\/n&quot;, path)\n  }\n}<\/code><\/pre>\n<p>\u8fd0\u884c\uff1a<\/p>\n<pre><code class=\"bash\">$ go run main.go \nfind ls in path:C:\/Program Files\/Git\/usr\/bin\/ls.exe\nno cmd not-exist: exec: &quot;not-exist&quot;: executable file not found in %PATH%<\/code><\/pre>\n<h2>\u5c01\u88c5<\/h2>\n<p>\u6267\u884c\u5916\u90e8\u547d\u4ee4\u7684\u6d41\u7a0b\u6bd4\u8f83\u56fa\u5b9a\uff1a<\/p>\n<ul>\n<li>\u8c03\u7528<code>exec.Command()<\/code>\u521b\u5efa\u547d\u4ee4\u5bf9\u8c61\uff1b<\/li>\n<li>\u8c03\u7528<code>Cmd.Run()<\/code>\u6267\u884c\u547d\u4ee4<\/li>\n<\/ul>\n<p>\u5982\u679c\u8981\u83b7\u53d6\u8f93\u51fa\uff0c\u9700\u8981\u8c03\u7528<code>CombinedOutput\/Output<\/code>\u4e4b\u7c7b\u7684\u65b9\u6cd5\uff0c\u6216\u8005\u624b\u52a8\u521b\u5efa<code>bytes.Buffer<\/code>\u5bf9\u8c61\u5e76\u8d4b\u503c\u7ed9<code>exec.Cmd<\/code>\u7684<code>Stdout<\/code>\u548c<code>Stderr<\/code>\u5b57\u6bb5\u3002\u4e3a\u4e86\u4f7f\u7528\u65b9\u4fbf\uff0c\u6211\u7f16\u5199\u4e86\u4e00\u4e2a\u5305<code>goexec<\/code>\u3002<\/p>\n<p>\u63a5\u53e3\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"go\">\/\/ \u6267\u884c\u547d\u4ee4\uff0c\u4e22\u5f03\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\nfunc RunCommand(cmd string, arg []string, opts ...Option) error\n\/\/ \u6267\u884c\u547d\u4ee4\uff0c\u4ee5[]byte\u7c7b\u578b\u8fd4\u56de\u8f93\u51fa\nfunc CombinedOutput(cmd string, arg []string, opts ...Option) ([]byte, error)\n\/\/ \u6267\u884c\u547d\u4ee4\uff0c\u4ee5string\u7c7b\u578b\u8fd4\u56de\u8f93\u51fa\nfunc CombinedOutputString(cmd string, arg []string, opts ...Option) (string, error)\n\/\/ \u6267\u884c\u547d\u4ee4\uff0c\u4ee5[]byte\u7c7b\u578b\u8fd4\u56de\u6807\u51c6\u8f93\u51fa\nfunc Output(cmd string, arg []string, opts ...Option) ([]byte, error)\n\/\/ \u6267\u884c\u547d\u4ee4\uff0c\u4ee5string\u7c7b\u578b\u8fd4\u56de\u6807\u51c6\u8f93\u51fa\nfunc OutputString(cmd string, arg []string, opts ...Option) (string, error)\n\/\/ \u6267\u884c\u547d\u4ee4\uff0c\u4ee5[]byte\u7c7b\u578b\u5206\u522b\u8fd4\u56de\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\nfunc SeparateOutput(cmd string, arg []string, opts ...Option) ([]byte, []byte, error)\n\/\/ \u6267\u884c\u547d\u4ee4\uff0c\u4ee5string\u7c7b\u578b\u5206\u522b\u8fd4\u56de\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\nfunc SeparateOutputString(cmd string, arg []string, opts ...Option) (string, string, error)<\/code><\/pre>\n<p>\u76f8\u8f83\u4e8e\u76f4\u63a5\u4f7f\u7528<code>os\/exec<\/code>\u5305\uff0c\u6211\u503e\u5411\u4e8e\u4e00\u6b21\u51fd\u6570\u8c03\u7528\u5c31\u80fd\u83b7\u5f97\u7ed3\u679c\u3002\u5bf9\u8f93\u5165\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u8fd9\u4e9b\u529f\u80fd\uff0c\u6211\u901a\u8fc7<strong>Option\u6a21\u5f0f<\/strong>\u6765\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n<pre><code class=\"go\">type Option func(*exec.Cmd)\n\nfunc WithStdin(stdin io.Reader) Option {\n  return func(c *exec.Cmd) {\n    c.Stdin = stdin\n  }\n}\n\nfunc Without(stdout io.Writer) Option {\n  return func(c *exec.Cmd) {\n    c.Stdout = stdout\n  }\n}\n\nfunc WithStderr(stderr io.Writer) Option {\n  return func(c *exec.Cmd) {\n    c.Stderr = stderr\n  }\n}\n\nfunc WithOutWriter(out io.Writer) Option {\n  return func(c *exec.Cmd) {\n    c.Stdout = out\n    c.Stderr = out\n  }\n}\n\nfunc WithEnv(key, value string) Option {\n  return func(c *exec.Cmd) {\n    c.Env = append(os.Environ(), fmt.Sprintf(&quot;%s=%s&quot;, key, value))\n  }\n}\n\nfunc applyOptions(cmd *exec.Cmd, opts []Option) {\n  for _, opt := range opts {\n    opt(cmd)\n  }\n}<\/code><\/pre>\n<p>\u4f7f\u7528\u975e\u5e38\u7b80\u5355\uff1a<\/p>\n<pre><code class=\"go\">func main() {\n  fmt.Println(goexec.CombinedOutputString(&quot;cal&quot;, nil, goexec.WithEnv(&quot;LANG&quot;, &quot;en_US.UTF-8&quot;)))\n}<\/code><\/pre>\n<p>\u6709\u4e00\u70b9\u6211\u4e0d\u592a\u6ee1\u610f\uff0c\u4e3a\u4e86\u4f7f\u7528Option\u6a21\u5f0f\uff0c\u672c\u6765\u53ef\u4ee5\u7528\u53ef\u53d8\u53c2\u6570\u6765\u4f20\u9012\u547d\u4ee4\u53c2\u6570\uff0c\u73b0\u5728\u53ea\u80fd\u7528\u5207\u7247\u4e86\uff0c\u5373\u4f7f\u4e0d\u9700\u8981\u6307\u5b9a\u53c2\u6570\uff0c\u4e5f\u5fc5\u987b\u8981\u4f20\u5165\u4e00\u4e2a<code>nil<\/code>\u3002\u6682\u65f6\u8fd8\u6ca1\u6709\u60f3\u5230\u6bd4\u8f83\u4f18\u96c5\u7684\u89e3\u51b3\u65b9\u6cd5\u3002<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u672c\u6587\u4ecb\u7ecd\u4e86\u4f7f\u7528<code>os\/exec<\/code>\u8fd9\u4e2a\u6807\u51c6\u5e93\u8c03\u7528\u5916\u90e8\u547d\u4ee4\u7684\u5404\u79cd\u59ff\u52bf\u3002\u540c\u65f6\u4e3a\u4e86\u4fbf\u4e8e\u4f7f\u7528\uff0c\u6211\u7f16\u5199\u4e86\u4e00\u4e2agoexec\u5305\u5c01\u88c5\u5bf9<code>os\/exec<\/code>\u7684\u8c03\u7528\u3002\u8fd9\u4e2a\u5305\u76ee\u524dfor\u6211\u81ea\u5df1\u4f7f\u7528\u662f\u6ca1\u6709\u95ee\u9898\u7684\uff0c\u5927\u5bb6\u6709\u5176\u4ed6\u9700\u6c42\u53ef\u4ee5\u63d0issue\u6216\u8005\u81ea\u5df1\u9b54\u6539\ud83d\ude04\u3002<\/p>\n<p>\u5927\u5bb6\u5982\u679c\u53d1\u73b0\u597d\u73a9\u3001\u597d\u7528\u7684 Go \u8bed\u8a00\u5e93\uff0c\u6b22\u8fce\u5230 Go \u6bcf\u65e5\u4e00\u5e93 GitHub \u4e0a\u63d0\u4ea4 issue\ud83d\ude04<\/p>\n<h2>\u53c2\u8003<\/h2>\n<ol>\n<li>Advanced command execution in go with os\/exec: <a href=\"https:\/\/link.segmentfault.com\/?enc=HeDvNo9AK4NIdTpyIiLYqg%3D%3D.aja%2B5%2FWYckeJOpMCWssCgHIY7MOqaqIAx79Xao3gh%2F%2FqdN4vXEa5F587a%2FGrOpzy%2FRHEcnnS70N2JwgreFQljajCrBTfMOyLtBc2LdliuoS%2Fc7Mh8MBWQt4ipc81k7cP4NtCssTh5PzluwXQyUZWsQ%3D%3D\" rel=\"nofollow\">https:\/\/blog.kowalczyk.info\/article\/wOYk\/advanced-command-execution-in-go-with-osexec.html<\/a><\/li>\n<li>goexec: <a href=\"https:\/\/link.segmentfault.com\/?enc=pbn%2F7jps8IDRnMLRxwpwhg%3D%3D.1kaO0pUl50w4ZHJi7b6F6rwRmE3l%2FOSDo65q2197k9vsbHXtOriYdwdQMygtsX1N\" rel=\"nofollow\">https:\/\/github.com\/darjun\/goexec<\/a><\/li>\n<li>Go \u6bcf\u65e5\u4e00\u5e93 GitHub\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=yk4NEFJ8eCXcB%2BI8BeO5EA%3D%3D.Bc5En1dN2tLN2CBtaD24SjhDZCJ%2FLFl%2FS5Nz0XKlKZ%2BB7FYfYVuvnTZU7vGJtNH3\" rel=\"nofollow\">https:\/\/github.com\/darjun\/go-daily-lib<\/a><\/li>\n<\/ol>\n<p>\u672c\u6587\u53c2\u4e0e\u4e86<a href=\"https:\/\/segmentfault.com\/a\/1190000042741155\">\u601d\u5426\u6280\u672f\u5f81\u6587<\/a>\uff0c\u6b22\u8fce\u6b63\u5728\u9605\u8bfb\u7684\u4f60\u4e5f\u52a0\u5165\u3002<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042773542\">https:\/\/segmentfault.com\/a\/1190000042773542<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f15\u5b50 \u5728\u5de5\u4f5c\u4e2d\uff0c\u6211\u65f6\u4e0d\u65f6\u5730\u4f1a\u9700\u8981\u5728Go\u4e2d\u8c03\u7528\u5916\u90e8\u547d\u4ee4\u3002\u524d\u6bb5\u65f6\u95f4\u6211\u505a\u4e86\u4e00\u4e2a\u5de5\u5177\uff0c\u5728\u9489\u9489\u7fa4\u4e2d\u6dfb\u52a0\u4e86\u4e00\u4e2a\u673a\u5668\u4eba\uff0c@\u8fd9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10006842","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006842","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10006842"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006842\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}