Execute php from java program-Collection of common programming errors
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 always use one of the execs that take a String[] cmdarray
Your args in this case are
"bash"
"-c"
"\"php /Users/phyrrus9/Projects/java-web/test.php | say\""
That is, you are running bash
— the first arg you are giving it is -c
and the second arg is the string.
Also see this answer to the more general question of how to Execute external program from Java.