Execute php from java program -


here code:

string cmd = "bash -c \"php /users/phyrrus9/projects/java-web/test.php | say\""; system.out.println("executing: " + cmd); runtime rt = runtime.getruntime(); process pr = rt.exec(cmd); 

yet, never executed. can run command shell , works fine. here contents of test.php

<?php      echo hello; ?> 

runtime.exec() not shell or command interpreter, , not treating command way think is. single-string argument version of exec() simple brain-dead split on spaces, quotes , escaped quotes meaningless; never making bash in way think.

always always use 1 of execs take string[] cmdarray

your args in case are

"bash" "-c" "\"php /users/phyrrus9/projects/java-web/test.php | say\"" 

that is, running bash -- first arg giving -c , second arg string.

also see this answer more general question of how execute external program java.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -