pbywater Posted May 22, 2007 Share Posted May 22, 2007 i wanna try get php to execute a command to a process/application running on a linux box(same computer). the application that is running is called asterisk. asterisk uses a CLI, how i normally do this is: Open a terminal type in: asterisk -r <--- connects to the CLI reload <----- reloads the config files exit <-- exits the terminal/CLI Link to comment https://forums.phpfreaks.com/topic/52461-connecting-to-a-program/ Share on other sites More sharing options...
maxim Posted May 22, 2007 Share Posted May 22, 2007 take a look at PHP's exec(); function Link to comment https://forums.phpfreaks.com/topic/52461-connecting-to-a-program/#findComment-258850 Share on other sites More sharing options...
pbywater Posted May 22, 2007 Author Share Posted May 22, 2007 ive tried that, but it doesnt seem to let me do anything other than system commands for example i can do exec('ls -A') that will work, but exec('asterisk -r') wont work Link to comment https://forums.phpfreaks.com/topic/52461-connecting-to-a-program/#findComment-258853 Share on other sites More sharing options...
trq Posted May 22, 2007 Share Posted May 22, 2007 asterisk is probably not in the apache users path for some reason. Try... <?php exec('/usr/bin/aterisk -are'); ?> Link to comment https://forums.phpfreaks.com/topic/52461-connecting-to-a-program/#findComment-258868 Share on other sites More sharing options...
pbywater Posted May 22, 2007 Author Share Posted May 22, 2007 tried, and failed, nothing outputs :S Link to comment https://forums.phpfreaks.com/topic/52461-connecting-to-a-program/#findComment-258947 Share on other sites More sharing options...
trq Posted May 22, 2007 Share Posted May 22, 2007 exec doesn't output anything (by default), what do you expect to receive? You might try system instead. Link to comment https://forums.phpfreaks.com/topic/52461-connecting-to-a-program/#findComment-258951 Share on other sites More sharing options...
utexas_pjm Posted May 22, 2007 Share Posted May 22, 2007 If you're trying to interactively use a program, by interactively, I mean send input and receive out butput via std in / out I'd use proc_open. Here's an example where I've used proc open to run php through the cgi binary and pass it output from std in then return the output sent by the cgi binary in std out: <?php // .. $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), ); $pipes = null; // Open our process, HTTP_CONF_CGI_EXECUTABLE holds the path to our program. $process = proc_open(HTTP_CONF_CGI_EXECUTABLE, $descriptorspec, $pipes); // This is our input pipe, anythinhg we write to here will get fed to program. $pipeIn = $pipes[0]; // This is our output pipe, anything the program writes will end up here. $pipeOut = $pipes[1]; // Write the contents of the request to the cgi bianry fwrite($pipeIn, $this->request->getContent()); // We're done with our input stream, so close it. fclose($pipeIn); // Get the output. $content = stream_get_contents($pipeOut); // We're done with our output stream, so close it. fclose($pipeOut); // Close the process. proc_close($process); ?> Best, Patrick Link to comment https://forums.phpfreaks.com/topic/52461-connecting-to-a-program/#findComment-259005 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.