{"id":1774,"date":"2020-04-18T08:39:16","date_gmt":"2020-04-18T00:39:16","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=1774"},"modified":"2020-04-18T08:39:16","modified_gmt":"2020-04-18T00:39:16","slug":"unity%e5%9c%a8unity%e4%b8%ad%e8%b0%83%e7%94%a8%e5%a4%96%e9%83%a8%e7%a8%8b%e5%ba%8f%e5%8f%8a%e6%89%b9%e5%a4%84%e7%90%86%e6%96%87%e4%bb%b6%e5%86%99%e8%87%aa%e5%8a%a8%e5%8c%96%e7%bc%96%e8%af%91","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=1774","title":{"rendered":"[Unity]\u5728Unity\u4e2d\u8c03\u7528\u5916\u90e8\u7a0b\u5e8f\u53ca\u6279\u5904\u7406\u6587\u4ef6,\u5199\u81ea\u52a8\u5316\u7f16\u8bd1\u811a\u672c\u9700\u8981\u6ce8\u610f\u7684\u5730\u65b9"},"content":{"rendered":"\n<p> \u5982\u679c\u8c03\u7528\u5916\u90e8\u666e\u901a\u5e94\u7528\u7a0b\u5e8f, \u6bd4\u5982notepad.exe \u8fd9\u6837\u8c03\u7528 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>static public bool ExecuteProgram(string exeFilename, string workDir, string args)\n{\n\tSystem.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();\n\tinfo.FileName = exeFilename;\n\tinfo.WorkingDirectory = workDir;\n\tinfo.RedirectStandardOutput = true;\n\tinfo.RedirectStandardError = true;\n\tinfo.Arguments = args;\n\tinfo.UseShellExecute = false;\n\tinfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;\n \n\tSystem.Diagnostics.Process task = null;\n \n\tbool rt = true;\n \n\ttry\n\t{\n\t\ttask = System.Diagnostics.Process.Start(info);\n\t\tif (task != null)\n\t\t{\n\t\t\ttask.WaitForExit(10000);\n\t\t} \n\t\telse\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t} \n\tcatch (Exception e)\n\t{\n\t\tDebug.LogError(\"Error: \" + e.ToString());\n\t\treturn false;\n\t} \n\tfinally\n\t{\n\t\tif (task != null &amp;&amp; task.HasExited)\n\t\t{\n\t\t\tstring output = task.StandardError.ReadToEnd();\n\t\t\tif (output.Length > 0)\n\t\t\t{\n\t\t\t\tDebug.LogError(output);\n\t\t\t}\n\t\t\t\n\t\t\toutput = task.StandardOutput.ReadToEnd();\n\t\t\tif (output.Length > 0)\n\t\t\t{\n\t\t\t\tDebug.Log(\"Error: \" + output);\n\t\t\t}\n\t\t\t\n\t\t\trt = (task.ExitCode == 0);\n\t\t}\n\t}\n \n\treturn rt;\n}<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u9700\u8981\u8c03\u7528Window\u7684\u6279\u5904\u7406\u6587\u4ef6BAT,&nbsp;<\/p>\n\n\n\n<p>\u6216\u8005\u542b\u6709\u63a7\u5236\u53f0\u8f93\u51fa\u7684\u7a0b\u5e8f,&nbsp;<\/p>\n\n\n\n<p>\u6216\u8005\u4f7f\u7528\u4e0a\u9762\u7684\u65b9\u6cd5\u5361\u6b7b, \u5219\u4f7f\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\u8fd0\u884c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>static bool ExecuteProgram(string exeFilename, string workDir, string args)\n{\n\tSystem.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();\n\tinfo.FileName = exeFilename;\n\tinfo.WorkingDirectory = workDir;\n\tinfo.UseShellExecute = true;\n\tinfo.Arguments = args;\n\tinfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;\n \n\tSystem.Diagnostics.Process task = null;\n\tbool rt = true;\n\ttry\n\t{\n\t\tDebug.Log(\"ExecuteProgram:\" + args);\n\t\t\n\t\ttask = System.Diagnostics.Process.Start(info);\n\t\tif (task != null)\n\t\t{\n\t\t\ttask.WaitForExit(100000);\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\tcatch (Exception e)\n\t{\n\t\tDebug.LogError(\"ExecuteProgram:\" + e.ToString());\n\t\treturn false;\n\t} \n\tfinally\n\t{\n\t\tif (task != null &amp;&amp; task.HasExited)\n\t\t{\n\t\t\trt = (task.ExitCode == 0);\n\t\t}\n\t}\n \n\treturn rt;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u8c03\u7528\u5916\u90e8\u666e\u901a\u5e94\u7528\u7a0b\u5e8f, \u6bd4\u5982notepad.exe \u8fd9\u6837\u8c03\u7528 \u5982\u679c\u9700\u8981\u8c03\u7528Window\u7684\u6279\u5904\u7406\u6587\u4ef6BAT, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1774"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1774"}],"version-history":[{"count":1,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1774\/revisions"}],"predecessor-version":[{"id":1775,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1774\/revisions\/1775"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}