{"id":3750,"date":"2014-03-30T05:11:53","date_gmt":"2014-03-30T05:11:53","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-pass-a-string-variable-as-a-shell-script-argument-collection-of-common-programming-errors\/"},"modified":"2014-03-30T05:11:53","modified_gmt":"2014-03-30T05:11:53","slug":"how-to-pass-a-string-variable-as-a-shell-script-argument-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-pass-a-string-variable-as-a-shell-script-argument-collection-of-common-programming-errors\/","title":{"rendered":"How to pass a string variable as a shell script argument?-Collection of common programming errors"},"content":{"rendered":"<p>You&#8217;ll want to call the command as follows:<\/p>\n<pre><code>Process process = new ProcessBuilder().command(\"sh\", \"\/path\/shell.sh\", var1, var2);\nScanner scan = new Scanner(process.getInputStream());\nwhile(scan.hasNextLine()) {\n    \/\/...\n}\n\/\/...\nscan.close();\nprocess.destroy();\n<\/code><\/pre>\n<p>You&#8217;ll probably want to wrap that in a <code>try-catch<\/code> block too.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;ll want to call the command as follows: Process process = new ProcessBuilder().command(&#8220;sh&#8221;, &#8220;\/path\/shell.sh&#8221;, var1, var2); Scanner scan = new Scanner(process.getInputStream()); while(scan.hasNextLine()) { \/\/&#8230; } \/\/&#8230; scan.close(); process.destroy(); You&#8217;ll probably want to wrap that in a try-catch block too.<\/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-3750","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3750","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=3750"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3750\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}