{"id":4643,"date":"2014-03-30T14:15:24","date_gmt":"2014-03-30T14:15:24","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/build-and-execute-a-bash-script-from-a-java-script-with-spaces-collection-of-common-programming-errors\/"},"modified":"2014-03-30T14:15:24","modified_gmt":"2014-03-30T14:15:24","slug":"build-and-execute-a-bash-script-from-a-java-script-with-spaces-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/build-and-execute-a-bash-script-from-a-java-script-with-spaces-collection-of-common-programming-errors\/","title":{"rendered":"build and execute a bash script from a java script with spaces-Collection of common programming errors"},"content":{"rendered":"<p>i am creating a java application which is will be GUI for a bash script..<\/p>\n<p>The application will be used browse the script location and enter 2 other parameters..<\/p>\n<p>and build and execute the command..<\/p>\n<p>so the execute part will be like this:<\/p>\n<pre><code>Runtime rt = Runtime.getRuntime();\nProcess pr = rt.exec(scriptPath + parameter1 + parameter2);\n<\/code><\/pre>\n<p>if the command work if the script&#8217;s location doesn&#8217;t has spaces in it..<\/p>\n<p>but when it has spaces it stops when it reach the first space.. and it gives me &#8220;java.io.IOException:&#8221; exeption..that the file is not found..<\/p>\n<p>i have tried replacing the spaces with backspace and space..<\/p>\n<pre><code>scriptPath.replace(\" \", \"\\\\ \")\n<\/code><\/pre>\n<p>i also tried adding quotes before and after the path<\/p>\n<pre><code>\"\\\"\" + scriptPath + \"\\\"\"\n<\/code><\/pre>\n<p>and i have tried them both together..<\/p>\n<pre><code>\"\\\"\" + scriptPath.replace(\" \", \"\\\\ \") + \"\\\"\"\n<\/code><\/pre>\n<p>but none of them had worked..<\/p>\n<p>any help will be appreciated..<\/p>\n<p>regards..<\/p>\n","protected":false},"excerpt":{"rendered":"<p>i am creating a java application which is will be GUI for a bash script.. The application will be used browse the script location and enter 2 other parameters.. and build and execute the command.. so the execute part will be like this: Runtime rt = Runtime.getRuntime(); Process pr = rt.exec(scriptPath + parameter1 + parameter2); [&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-4643","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4643","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=4643"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4643\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}