Passing and Reading values using child_process spawn in node js

908 views Asked by At

I am Developing a Node js Application in which i need to invoke and execute a .php file and i have implemented it successfully, but the problem is when i am trying to send values to php file i am unable to read it.

Here is the sample code that i am using to invoke a php file

var spawn = require("child_process").spawn
    router.post('/textphp', function(req, res){
        var php = spawn('/usr/bin/php',['./public_html/files/demo_php_script.php'],
            {
                env:
                {
                    foo: "value"
                }
            });
        php.stdout.on('data', function(data)
        {
            console.log(data.toString());
        });
    });

And here is the format i which i am trying to read the passed data in a php file

<?php
   echo $_ENV['foo']
?>

I have searched every where and i cannot find a solution, any response will be greatly thankful.

0

There are 0 answers