{"id":4930,"date":"2014-03-30T17:02:58","date_gmt":"2014-03-30T17:02:58","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/java-run-command-line-which-contains-spaces-collection-of-common-programming-errors\/"},"modified":"2014-03-30T17:02:58","modified_gmt":"2014-03-30T17:02:58","slug":"java-run-command-line-which-contains-spaces-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/java-run-command-line-which-contains-spaces-collection-of-common-programming-errors\/","title":{"rendered":"Java run command line which contains spaces-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to run a .bat file from my Java app. I&#8217;ve tried all the methods I could find, but none seems to work.<\/p>\n<p>The problem is that the path to the .bat file containing spaces.<\/p>\n<p>I&#8217;m using this method now so I can see the results in my Eclipse console http:\/\/viralpatel.net\/blogs\/how-to-execute-command-prompt-command-view-output-java\/<\/p>\n<p>My actual code is:<\/p>\n<pre><code>Runtime rt = Runtime.getRuntime();\nString processString = \"cmd \/c \\\"\" + homeFolder.getAbsolutePath() + SETUP_FILE + \"\\\" \\\"\" + homeFolder.getAbsolutePath() + \"\\\"\";\n    try {\n        Process proc = rt.exec(processString);\n    ...\n    }\n<\/code><\/pre>\n<p>I&#8217;ve tried with escaping the quotes, without escaping quotes, separating the string into <code>String[]<\/code> and placing each space separated command its own cell:<\/p>\n<pre><code>{ \"cmd\", \"\/c\", \\\"\" + homeFolder.getAbsolutePath() + SETUP_FILE + \"\\\" ... };\n<\/code><\/pre>\n<p>Again, with and without escaping the quotes: nothing works.<\/p>\n<p>I also tried hard-coding the paths to both the array and the string. Same results every time.<\/p>\n<pre><code>homeFolder = C:\\Users\\La bla bla\\workspace\\ToolMaker\\bin\\\nSETUP_FILE = setup.bat\n<\/code><\/pre>\n<p>The whole command is this:<\/p>\n<pre><code>cmd \/c \"C:\\Users\\La bla bla\\workspace\\ToolMaker\\bin\\setup.bat\" \"C:\\Users\\La bla bla\\workspace\\ToolMaker\\bin\"\n<\/code><\/pre>\n<p>Again, with or without quotes, same output:<\/p>\n<pre><code>Output: \nError: 'C:\\Users\\La' is not recognized as an internal or external command,operable program or batch file.\n<\/code><\/pre>\n<p>Obviously I&#8217;m running on Windows (7, 64 bit professional). Java 7<\/p>\n<p>I saw a few people said they had this issues before, but I couldn&#8217;t find an answer on how to get around that.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to run a .bat file from my Java app. I&#8217;ve tried all the methods I could find, but none seems to work. The problem is that the path to the .bat file containing spaces. I&#8217;m using this method now so I can see the results in my Eclipse console http:\/\/viralpatel.net\/blogs\/how-to-execute-command-prompt-command-view-output-java\/ My actual code [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4930","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4930"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4930\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}