{"id":2602,"date":"2022-08-30T15:26:14","date_gmt":"2022-08-30T15:26:14","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/04\/execute-php-from-java-program-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:26:14","modified_gmt":"2022-08-30T15:26:14","slug":"execute-php-from-java-program-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/execute-php-from-java-program-collection-of-common-programming-errors\/","title":{"rendered":"Execute php from java program-Collection of common programming errors"},"content":{"rendered":"<p><code>Runtime.exec()<\/code> is not a shell or a command interpreter, and is not treating your command the way you think it is. The single-String argument version of exec() does a simple brain-dead split on spaces, so your quotes and escaped quotes are meaningless; they are never making it to bash in the way you think.<\/p>\n<p>Always <em>always<\/em> use one of the execs that take a <code>String[] cmdarray<\/code><\/p>\n<p>Your args in this case are<\/p>\n<pre><code>\"bash\"\n\"-c\"\n\"\\\"php \/Users\/phyrrus9\/Projects\/java-web\/test.php | say\\\"\"\n<\/code><\/pre>\n<p>That is, you are running <code>bash<\/code> &#8212; the first arg you are giving it is <code>-c<\/code> and the second arg is the string.<\/p>\n<p>Also see this answer to the more general question of how to Execute external program from Java.<\/p>\n<p id=\"rop\"><small>Originally posted 2014-02-04 02:42:00. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Runtime.exec() is not a shell or a command interpreter, and is not treating your command the way you think it is. The single-String argument version of exec() does a simple brain-dead split on spaces, so your quotes and escaped quotes are meaningless; they are never making it to bash in the way you think. Always [&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-2602","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2602","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=2602"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2602\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}