{"id":276,"date":"2008-09-17T08:35:14","date_gmt":"2008-09-17T07:35:14","guid":{"rendered":"http:\/\/thekua.com\/atwork\/2008\/09\/17\/executing-native-processes-in-java-on-windows\/"},"modified":"2008-09-17T08:35:14","modified_gmt":"2008-09-17T07:35:14","slug":"executing-native-processes-in-java-on-windows","status":"publish","type":"post","link":"https:\/\/thekua.com\/atwork\/2008\/09\/executing-native-processes-in-java-on-windows\/","title":{"rendered":"Executing native processes in Java on Windows"},"content":{"rendered":"<p>This is probably something that old timers in Java will probably know, so I&#8217;m posting this more for my reference. Trying to execute:<\/p>\n<pre>Runtime.getRuntime().exec(\"dir\");<\/pre>\n<p>results in the following stack trace.<\/p>\n<pre>java.io.IOException: CreateProcess: dir error=2\r\n  at java.lang.ProcessImpl.create(Native Method)\r\n  at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)\r\n  at java.lang.ProcessImpl.start(ProcessImpl.java:30)\r\n  at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)\r\n  at java.lang.Runtime.exec(Runtime.java:591)\r\n  at java.lang.Runtime.exec(Runtime.java:429)\r\n  at java.lang.Runtime.exec(Runtime.java:326)\r\n<\/pre>\n<p>After doing some reading <\/p>\n<pre>error=2<\/pre>\n<p> apparently means file not found. The fix for something like this is to first pass everything to the windows command line shell (cmd.exe on windows xp). This seems to do the job better:<\/p>\n<pre>Runtime.getRuntime().exec(\"cmd \/c dir\");<\/pre>\n<p>The slash-C means &#8220;Carries out the command specified by string and then terminates&#8221;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is probably something that old timers in Java will probably know, so I&#8217;m posting this more for my reference. Trying to execute: Runtime.getRuntime().exec(&#8220;dir&#8221;); results in the following stack trace. java.io.IOException: CreateProcess: dir error=2 at java.lang.ProcessImpl.create(Native Method) at java.lang.ProcessImpl.(ProcessImpl.java:81) at java.lang.ProcessImpl.start(ProcessImpl.java:30) at java.lang.ProcessBuilder.start(ProcessBuilder.java:451) at java.lang.Runtime.exec(Runtime.java:591) at java.lang.Runtime.exec(Runtime.java:429) at java.lang.Runtime.exec(Runtime.java:326) After doing some reading error=2 apparently [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,35],"tags":[],"class_list":["post-276","post","type-post","status-publish","format-standard","hentry","category-development","category-java","post-preview"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Executing native processes in Java on Windows - patkua@work<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thekua.com\/atwork\/2008\/09\/executing-native-processes-in-java-on-windows\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Executing native processes in Java on Windows - patkua@work\" \/>\n<meta property=\"og:description\" content=\"This is probably something that old timers in Java will probably know, so I&#8217;m posting this more for my reference. Trying to execute: Runtime.getRuntime().exec(&quot;dir&quot;); results in the following stack trace. java.io.IOException: CreateProcess: dir error=2 at java.lang.ProcessImpl.create(Native Method) at java.lang.ProcessImpl.(ProcessImpl.java:81) at java.lang.ProcessImpl.start(ProcessImpl.java:30) at java.lang.ProcessBuilder.start(ProcessBuilder.java:451) at java.lang.Runtime.exec(Runtime.java:591) at java.lang.Runtime.exec(Runtime.java:429) at java.lang.Runtime.exec(Runtime.java:326) After doing some reading error=2 apparently [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/thekua.com\/atwork\/2008\/09\/executing-native-processes-in-java-on-windows\/\" \/>\n<meta property=\"og:site_name\" content=\"patkua@work\" \/>\n<meta property=\"article:published_time\" content=\"2008-09-17T07:35:14+00:00\" \/>\n<meta name=\"author\" content=\"Patrick\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@patkua\" \/>\n<meta name=\"twitter:site\" content=\"@patkua\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Patrick\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/09\\\/executing-native-processes-in-java-on-windows\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/09\\\/executing-native-processes-in-java-on-windows\\\/\"},\"author\":{\"name\":\"Patrick\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#\\\/schema\\\/person\\\/c942203c9ed3ff9e21c6c49a996ea3ae\"},\"headline\":\"Executing native processes in Java on Windows\",\"datePublished\":\"2008-09-17T07:35:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/09\\\/executing-native-processes-in-java-on-windows\\\/\"},\"wordCount\":88,\"commentCount\":4,\"articleSection\":[\"Development\",\"Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/09\\\/executing-native-processes-in-java-on-windows\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/09\\\/executing-native-processes-in-java-on-windows\\\/\",\"url\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/09\\\/executing-native-processes-in-java-on-windows\\\/\",\"name\":\"Executing native processes in Java on Windows - patkua@work\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#website\"},\"datePublished\":\"2008-09-17T07:35:14+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#\\\/schema\\\/person\\\/c942203c9ed3ff9e21c6c49a996ea3ae\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/09\\\/executing-native-processes-in-java-on-windows\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/09\\\/executing-native-processes-in-java-on-windows\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/2008\\\/09\\\/executing-native-processes-in-java-on-windows\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Executing native processes in Java on Windows\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#website\",\"url\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/\",\"name\":\"patkua@work\",\"description\":\"The intersection of technology and leadership\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/#\\\/schema\\\/person\\\/c942203c9ed3ff9e21c6c49a996ea3ae\",\"name\":\"Patrick\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g\",\"caption\":\"Patrick\"},\"sameAs\":[\"http:\\\/\\\/thekua.com\\\/atwork\"],\"url\":\"https:\\\/\\\/thekua.com\\\/atwork\\\/author\\\/patrick\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Executing native processes in Java on Windows - patkua@work","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/thekua.com\/atwork\/2008\/09\/executing-native-processes-in-java-on-windows\/","og_locale":"en_US","og_type":"article","og_title":"Executing native processes in Java on Windows - patkua@work","og_description":"This is probably something that old timers in Java will probably know, so I&#8217;m posting this more for my reference. Trying to execute: Runtime.getRuntime().exec(\"dir\"); results in the following stack trace. java.io.IOException: CreateProcess: dir error=2 at java.lang.ProcessImpl.create(Native Method) at java.lang.ProcessImpl.(ProcessImpl.java:81) at java.lang.ProcessImpl.start(ProcessImpl.java:30) at java.lang.ProcessBuilder.start(ProcessBuilder.java:451) at java.lang.Runtime.exec(Runtime.java:591) at java.lang.Runtime.exec(Runtime.java:429) at java.lang.Runtime.exec(Runtime.java:326) After doing some reading error=2 apparently [&hellip;]","og_url":"https:\/\/thekua.com\/atwork\/2008\/09\/executing-native-processes-in-java-on-windows\/","og_site_name":"patkua@work","article_published_time":"2008-09-17T07:35:14+00:00","author":"Patrick","twitter_card":"summary_large_image","twitter_creator":"@patkua","twitter_site":"@patkua","twitter_misc":{"Written by":"Patrick","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/thekua.com\/atwork\/2008\/09\/executing-native-processes-in-java-on-windows\/#article","isPartOf":{"@id":"https:\/\/thekua.com\/atwork\/2008\/09\/executing-native-processes-in-java-on-windows\/"},"author":{"name":"Patrick","@id":"https:\/\/thekua.com\/atwork\/#\/schema\/person\/c942203c9ed3ff9e21c6c49a996ea3ae"},"headline":"Executing native processes in Java on Windows","datePublished":"2008-09-17T07:35:14+00:00","mainEntityOfPage":{"@id":"https:\/\/thekua.com\/atwork\/2008\/09\/executing-native-processes-in-java-on-windows\/"},"wordCount":88,"commentCount":4,"articleSection":["Development","Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/thekua.com\/atwork\/2008\/09\/executing-native-processes-in-java-on-windows\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/thekua.com\/atwork\/2008\/09\/executing-native-processes-in-java-on-windows\/","url":"https:\/\/thekua.com\/atwork\/2008\/09\/executing-native-processes-in-java-on-windows\/","name":"Executing native processes in Java on Windows - patkua@work","isPartOf":{"@id":"https:\/\/thekua.com\/atwork\/#website"},"datePublished":"2008-09-17T07:35:14+00:00","author":{"@id":"https:\/\/thekua.com\/atwork\/#\/schema\/person\/c942203c9ed3ff9e21c6c49a996ea3ae"},"breadcrumb":{"@id":"https:\/\/thekua.com\/atwork\/2008\/09\/executing-native-processes-in-java-on-windows\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/thekua.com\/atwork\/2008\/09\/executing-native-processes-in-java-on-windows\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/thekua.com\/atwork\/2008\/09\/executing-native-processes-in-java-on-windows\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/thekua.com\/atwork\/"},{"@type":"ListItem","position":2,"name":"Executing native processes in Java on Windows"}]},{"@type":"WebSite","@id":"https:\/\/thekua.com\/atwork\/#website","url":"https:\/\/thekua.com\/atwork\/","name":"patkua@work","description":"The intersection of technology and leadership","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/thekua.com\/atwork\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/thekua.com\/atwork\/#\/schema\/person\/c942203c9ed3ff9e21c6c49a996ea3ae","name":"Patrick","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2ef85a5f91c2aac13efb3ac90077b4db7f8883cafd6e60f2bcecba6b092d4011?s=96&d=mm&r=g","caption":"Patrick"},"sameAs":["http:\/\/thekua.com\/atwork"],"url":"https:\/\/thekua.com\/atwork\/author\/patrick\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/posts\/276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/comments?post=276"}],"version-history":[{"count":0,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/posts\/276\/revisions"}],"wp:attachment":[{"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/media?parent=276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/categories?post=276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thekua.com\/atwork\/wp-json\/wp\/v2\/tags?post=276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}