{"id":4733,"date":"2014-03-30T15:01:00","date_gmt":"2014-03-30T15:01:00","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/executing-external-program-in-java-collection-of-common-programming-errors\/"},"modified":"2014-03-30T15:01:00","modified_gmt":"2014-03-30T15:01:00","slug":"executing-external-program-in-java-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/executing-external-program-in-java-collection-of-common-programming-errors\/","title":{"rendered":"Executing external program in Java-Collection of common programming errors"},"content":{"rendered":"<p>Make either an script for bash:<\/p>\n<pre><code>\"\/bin\/bash\" \"-c\" \"cut file.txt -d' ' -f1-2  &gt; hits.txt\"\n<\/code><\/pre>\n<p>or split<\/p>\n<pre><code>\"cut\" \"file.txt\" \"-d\" \"' '\" \"-f\" \"1-2\" \n<\/code><\/pre>\n<p>The error message clearly says:<\/p>\n<pre><code>Cannot run program \"cut file.txt\"\n<\/code><\/pre>\n<p>so it interprets &#8220;cut file.txt&#8221; as a single programname with a blank inside.<\/p>\n<p>Your problem starts with the redirection, because you can&#8217;t redirect the output that way:<\/p>\n<pre><code>\"cut\" \"file.txt\" \"-d\" \"' '\" \"-f\" \"1-2\" \"&gt;\" \"hits.txt\"\n<\/code><\/pre>\n<p>You have to handle input and output streams. It might be a better idea to implement <code>cut<\/code> in Java, to get a portable solution, or call a script which the user may specify on commandline or in a config file, so that it can be adapted for Windows or other platforms.<\/p>\n<p>Calling \/bin\/bash and redirecting there should work &#8211; on unix like systems.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Make either an script for bash: &#8220;\/bin\/bash&#8221; &#8220;-c&#8221; &#8220;cut file.txt -d&#8217; &#8216; -f1-2 &gt; hits.txt&#8221; or split &#8220;cut&#8221; &#8220;file.txt&#8221; &#8220;-d&#8221; &#8220;&#8216; &#8216;&#8221; &#8220;-f&#8221; &#8220;1-2&#8221; The error message clearly says: Cannot run program &#8220;cut file.txt&#8221; so it interprets &#8220;cut file.txt&#8221; as a single programname with a blank inside. Your problem starts with the redirection, because you [&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-4733","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4733","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=4733"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4733\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}