Jump to content

How to get PHP to interact with bash code ?


tmyonline

Recommended Posts

Hi guys, thanks for the prompt response.

 

I'm comfortable with PHP but I'm a newbie at bash.  Samshel, in your example

 

#!/bin/bash       

        echo Hello World

/usr/bin/php test.php parameter1 parameter2

 

you are passing two parameters, namely parameter1 and parameter2, to a PHP file called "test.php" located in the php directory under bin.  Is that what you meant ?  If so, if I run test.php, it will automatically output the results which made use of parameter1 and parameter2 as the inputs ?

 

The point I'm trying to make sure here is that I don't have to run each program, bash & PHP, individually.  So, if I run test.php and if it automatically executes the bash program for the output parameter1 and parameter2 which serve as the input for the test.php program, then that's great.  But, is it the case though ?  Many thanks.

 

Hi corbin, yeah, piping could be another method to achieve this.  Do you have the link to this material.  I searched Google on php://stdin but it didn't point me to the right place.  Many thanks.

http://php.net/wrappers.php

 

 

php://stdin is just a stream wrapper.  You would basically treat it like any other stream (like a file stream for example).

 

 

 

 

As for parameters passed on the command line, you would use $_SERVER['argc'] and $_SERVER['argv'] (or you could use $argc and $argv).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.