{"id":2272,"date":"2021-09-15T12:06:40","date_gmt":"2021-09-15T03:06:40","guid":{"rendered":"https:\/\/www.d0web.com\/?p=2272"},"modified":"2021-09-15T12:06:40","modified_gmt":"2021-09-15T03:06:40","slug":"powershell%e3%81%a7%e5%a4%96%e9%83%a8%e3%83%97%e3%83%ad%e3%82%bb%e3%82%b9%e3%82%92%e5%ae%9f%e8%a1%8c%e3%81%97%e3%81%a6%e7%b5%82%e4%ba%86%e3%82%b3%e3%83%bc%e3%83%89%e3%82%92%e5%8f%96%e5%be%97%e3%81%99","status":"publish","type":"post","link":"https:\/\/www.d0web.com\/blog\/archives\/2272","title":{"rendered":"PowerShell\u3067\u5916\u90e8\u30d7\u30ed\u30bb\u30b9\u3092\u5b9f\u884c\u3057\u3066\u7d42\u4e86\u30b3\u30fc\u30c9\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<h2>\u3042\u3089\u3059\u3058<\/h2>\n<p>Start-Process\u3067\u5b9f\u884c\u3057\u305f\u5916\u90e8\u30d7\u30ed\u30bb\u30b9\u306e\u7d42\u4e86\u30b3\u30fc\u30c9\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u5b58\u5728\u305b\u305a\u53d6\u5f97\u3067\u304d\u306a\u3044\u554f\u984c\u306b\u76f4\u9762\u3002<\/p>\n<pre><code class=\"language-powershell\">$proc = Start-Process -FilePath &#039;Unko.exe&#039; -NoNewWindow -Wait\nWrite-Host $proc.ExitCode   # Check ExitCode.<\/code><\/pre>\n<pre><code class=\"language-plane\">\u3053\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u30d7\u30ed\u30d1\u30c6\u30a3 &#039;ExitCode&#039; \u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3002\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u5b58\u5728\u3059\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n\n+     Write-Host $proc.ExitCode\n+     ~~~~~~~~~~~~~~~~~~~~~~~~~\n    + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException\n    + FullyQualifiedErrorId : PropertyNotFoundStrict<\/code><\/pre>\n<h2>\u53c2\u8003<\/h2>\n<ul>\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/10262231\/obtaining-exitcode-using-start-process-and-waitforexit-instead-of-wait\">powershell &#8211; Obtaining ExitCode using Start-Process and WaitForExit instead of -Wait &#8211; Stack Overflow<\/a><\/li>\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/44057728\/start-process-system-diagnostics-process-exitcode-is-null-with-nonewwindow\">.net &#8211; Start-Process \/ System.Diagnostics.Process ExitCode is $null with -NoNewWindow &#8211; Stack Overflow<\/a><\/li>\n<\/ul>\n<h2>\u65b9\u6cd5<\/h2>\n<p>Start-Process\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u306b <code>-PassThru<\/code> \u3092\u3064\u3051\u308b\u3068ExitCode\u304cnull\u306b\u306a\u3089\u306a\u304f\u306a\u308b\u3002<\/p>\n<pre><code class=\"language-powershell\">$proc = Start-Process -FilePath &#039;Unko.exe&#039; -NoNewWindow -PassThru -Wait\nWrite-Host $proc.ExitCode   # Check ExitCode.<\/code><\/pre>\n<p>\u305f\u3060\u3057\u3053\u306e\u65b9\u6cd5\u3060\u3068\u5916\u90e8\u30d7\u30ed\u30bb\u30b9\u306e\u5b9f\u884c\u901f\u5ea6\u304c\u9045\u304f\u306a\u308a\uff08\u7406\u7531\u306f\u672a\u8abf\u67fb&#8230;\u3002\uff09\u3001<br \/>\nFor\u30eb\u30fc\u30d7\u7b49\u3067\u4f55\u56de\u3082\u5b9f\u884c\u3059\u308b\u5834\u5408\u306b\u554f\u984c\u304c\u51fa\u308b\u305f\u3081\u6b21\u306e\u3088\u3046\u306b<code>-Wait<\/code>\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u629c\u3044\u3066\u30d7\u30ed\u30bb\u30b9\u30cf\u30f3\u30c9\u30eb\u3092\u30ad\u30e3\u30c3\u30b7\u30e5\u3057\u3066\u5bfe\u51e6\u3059\u308b\u3002<\/p>\n<pre><code class=\"language-powershell\">$proc = Start-Process -FilePath &#039;Unko.exe&#039; -NoNewWindow -PassThru\n$handle = $proc.Handle # cache proc.Handle\n$proc.WaitForExit()\nWrite-Host $proc.ExitCode   # Check ExitCode.<\/code><\/pre>\n<h2>\u304a\u308f\u3044<\/h2>\n<p>PowerShell\u7d4c\u9a13\u304c\u5e74\u9f62\u306b\u4f34\u3063\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u306a\u305cWait\u3092\u5165\u308c\u308b\u3068\u5b9f\u52b9\u901f\u5ea6\u4f4e\u4e0b\u306b\u3064\u306a\u304c\u308b\u304b\u3001<br \/>\n\u306a\u305c\u30d7\u30ed\u30bb\u30b9\u30cf\u30f3\u30c9\u30eb\u3092\u30ad\u30e3\u30c3\u30b7\u30e5\u3059\u308b\u3068ExitCode\u304cnull\u306b\u306a\u3089\u306a\u3044\u304b\u3092\u3061\u3083\u3093\u3068\u3057\u305f\u7406\u7531\u3092\u8abf\u3079\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u304a\u308f\u3044<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3042\u3089\u3059\u3058 Start-Process\u3067\u5b9f\u884c\u3057\u305f\u5916\u90e8\u30d7\u30ed\u30bb\u30b9\u306e\u7d42\u4e86\u30b3\u30fc\u30c9\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u5b58\u5728\u305b\u305a\u53d6\u5f97\u3067\u304d\u306a\u3044\u554f\u984c\u306b\u76f4\u9762\u3002 $&#46;&#46;&#46;<\/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,11],"tags":[21],"class_list":["post-2272","post","type-post","status-publish","format-standard","hentry","category-4","category-11","tag-powershell"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.d0web.com\/blog\/wp-json\/wp\/v2\/posts\/2272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.d0web.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.d0web.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.d0web.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.d0web.com\/blog\/wp-json\/wp\/v2\/comments?post=2272"}],"version-history":[{"count":29,"href":"https:\/\/www.d0web.com\/blog\/wp-json\/wp\/v2\/posts\/2272\/revisions"}],"predecessor-version":[{"id":2304,"href":"https:\/\/www.d0web.com\/blog\/wp-json\/wp\/v2\/posts\/2272\/revisions\/2304"}],"wp:attachment":[{"href":"https:\/\/www.d0web.com\/blog\/wp-json\/wp\/v2\/media?parent=2272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.d0web.com\/blog\/wp-json\/wp\/v2\/categories?post=2272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.d0web.com\/blog\/wp-json\/wp\/v2\/tags?post=2272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}