{"id":4814,"date":"2014-03-30T15:34:37","date_gmt":"2014-03-30T15:34:37","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/java-normalize-file-path-for-external-execution-collection-of-common-programming-errors\/"},"modified":"2014-03-30T15:34:37","modified_gmt":"2014-03-30T15:34:37","slug":"java-normalize-file-path-for-external-execution-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/java-normalize-file-path-for-external-execution-collection-of-common-programming-errors\/","title":{"rendered":"Java normalize file path for external execution-Collection of common programming errors"},"content":{"rendered":"<p>Instead of using <code>exec(String)<\/code>, use <code>exec(String[])<\/code> (from <code>Runtime<\/code>). The second form lets you supply all arguments individually, that way Java does not need to parse them further, and will not split on spaces.<\/p>\n<p>Example:<\/p>\n<pre><code>  Process proc = Runtime.getRuntime().exec(\n    new String[]{\"ffmpeg\", \"-ac\", \"1\", \"-i\",videoFile.getPath()), audioFile.getPath()}\n  );\n<\/code><\/pre>\n<p>You should always use the second form if your arguments may contain spaces, otherwise your command may break.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Instead of using exec(String), use exec(String[]) (from Runtime). The second form lets you supply all arguments individually, that way Java does not need to parse them further, and will not split on spaces. Example: Process proc = Runtime.getRuntime().exec( new String[]{&#8220;ffmpeg&#8221;, &#8220;-ac&#8221;, &#8220;1&#8221;, &#8220;-i&#8221;,videoFile.getPath()), audioFile.getPath()} ); You should always use the second form if your arguments [&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-4814","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4814","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=4814"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4814\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}