{"id":4962,"date":"2014-03-30T17:12:42","date_gmt":"2014-03-30T17:12:42","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-run-cygwin-script-from-java-collection-of-common-programming-errors\/"},"modified":"2014-03-30T17:12:42","modified_gmt":"2014-03-30T17:12:42","slug":"how-to-run-cygwin-script-from-java-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-run-cygwin-script-from-java-collection-of-common-programming-errors\/","title":{"rendered":"how to run cygwin script from java-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to run a bash script from a Java program I&#8217;m writing in windows. I&#8217;ve been trying to use the Runtime object to get a process to work, and my program compiles and runs without exceptions, but my simple test script, which just makes a directory, is not being executed.<\/p>\n<p>Here&#8217;s what I&#8217;ve got so far:<\/p>\n<pre><code>String cmmd[] = new String[3];\n    cmmd[0] = \"C:\\\\cygwin\\\\bin\\\\bash.exe\";\n    cmmd[1] = \"cd C:\/Users\/pro-services\/Desktop\/projects\/github\/cygwin\";\n    cmmd[2] = \"bash TEST.sh\";\n\n    Runtime rt= Runtime.getRuntime();\n    Process proc = rt.exec(cmmd);\n<\/code><\/pre>\n<p>This is basically a mix of different things I&#8217;ve found in forums around the net, but I guess I just don&#8217;t really understand what is happening with the Process class (and I only have a basic idea about the Runtime class).<\/p>\n<p>I also found this, and plugged my own stuff in where I thought it should go:<\/p>\n<pre><code>Runtime.getRuntime().exec(new String[]{\"C:\\\\cygwin\\\\bin\\\\bash.exe\",\n                                                    \"-c\", \"c:\\\\cygwin\\\\bin\\\\run.exe -p \/bin bash C:\\\\Users\\\\pro-services\\\\Desktop\\\\projects\\\\github\\\\cygwin\\\\TEST.sh\"},\n                                      new String[]{\"PATH=\/cygdrive\/c\/cygwin\/bin\"});\n<\/code><\/pre>\n<p>Here I&#8217;m not sure what the <code>\"-c\"<\/code> and <code>\"-p\"<\/code> strings represent, but I just went with it. At first it looked like I could just plug in the sequential commands that I want the Runtime\/Process object to execute, in essence creating a &#8220;script&#8221; to run my script. But it now seems that there&#8217;s more to it&#8230;<\/p>\n<p>I&#8217;m just shooting in the dark at this point, and I have tried to understand the documentation but I&#8217;m lost. Any help would be appreciated. Thanks )))<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to run a bash script from a Java program I&#8217;m writing in windows. I&#8217;ve been trying to use the Runtime object to get a process to work, and my program compiles and runs without exceptions, but my simple test script, which just makes a directory, is not being executed. Here&#8217;s what I&#8217;ve got [&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-4962","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4962","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=4962"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4962\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4962"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4962"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}