Re: Calling an executable for processing some data sent from PHP
| From: | Daniel Brown | Date: | Fri, 15 Jun 2007 20:52:04 +0000 |
| Subject: | Re: Calling an executable for processing some data sent from PHP | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-257127@lists.php.net to get a copy of this message | ||
On 6/15/07, Dan <frozendice@gmail.com> wrote:
Will that script also work on Apache in Windows? OS X? Just checking because the backend and front end both need to be able to be installed on any OS. Also I looked at exec(), system(), and passthru(); they all let you execute a executable file but I don't see any way of passing parameters in any of those functions, can you do that? - Daniel ""Daniel Brown"" <parasane@gmail.com> wrote in message news:ab5568160706151311m3327bbccha02e3f5ca96255d8@mail.gmail.com... On 6/15/07, Dan <frozendice@gmail.com> wrote:Yeah, the first parameter of each function, where you call the executable directly, just has to include the parameters you want to pass to the binary. For example, if you wanted to do the following:RTFM for exec(), system(), passthru(), et cetera. <? exec('pascal-file '.$_POST['user_command'],$ret); $ret == 1 ? 'Error detected' ? ''; ?> -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpOk, so I have a PHP script, and I also have a program written in Pascal, it's compiled in the native executable for whatever OS the server is running. I want to have the user input info and then send that info to the Pascal program to call a function and send the info as parameters. Is there any sort of server side call I can do to do this? Or is my only option making some sort of connection such as SOAP between PHP and the Program? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
netstat -pnt
ls -al|grep -i php
mv file1.php backups/file2.php
You would (respectively) simply do the following:
exec('netstat -pnt',$ret);
exec('ls -al|grep -i php',$ret);
exec('mv file1.php backups/file2.php',$ret);
Then just eval $ret to see if it was successful (0) or not (1).
If you wanted to allow a user to specify parameters, it would be
done like so:
[PHP]
L> File: form.php
<?
if($_POST['parameters']) {
exec('/path/to/pascal-binary '.escapeshellarg($_POST['parameters']),$ret);
$ret == 0 ? "Success!" : "Failure!";
exit;
}
?>
<FORM METHOD="POST" ACTION="<?=$_SERVER['PHP_SELF;?>">
Parameters: <INPUT TYPE="TEXT" NAME="parameters"><BR />
<INPUT TYPE="SUBMIT" VALUE="Process Now">
</FORM>
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107