0

If I want to call/execute node test.js file into demo.php file. I found one function called exec() which will execute the node command into PHP.

Here is my file where I have created two files are as follow.

test.js

console.log('welcome');

where I have simply added the message called "welcome". Now I have created one more file for PHP where I want to call above file and print the above message while I am called below file.

demp.php

<?php
       $result = exec('node detail.js &',$out);
       print_r($result);
       print_r($out);
?>

Problem is that when I execute PHP file "http://localhost/demo.php" the output like below

Array ( ) 

and I cannot find any message in console.log.

halfer
  • 19,824
  • 17
  • 99
  • 186
Codebrekers
  • 754
  • 1
  • 11
  • 29
  • 2
    node runs in the background because of `&` in `node detail.js &` – hisener Oct 27 '17 at 06:32
  • @hisener Oky then how may i check that file call or not and my node file message is display in console log or not..? – Codebrekers Oct 27 '17 at 06:34
  • I am not a php guy but I found this. Please take a look: http://php.net/manual/en/function.shell-exec.php It says `Execute command via shell and return the complete output as a string` – hisener Oct 27 '17 at 06:39
  • @hisener ok thanks for answer but let me clear the thing is shell-exec and exec both are different function check the link https://stackoverflow.com/questions/7093860/php-shell-exec-vs-exec – Codebrekers Oct 27 '17 at 06:43

0 Answers0