从php Web应用程序执行节点脚本(Windows)

I have a php web application and on one of the route I try to execute node script.

Node script location: C:\Users\meusr\Workspace\www\myproject\directImport.js

I have configured my package.json, such that npm start executes above script.

php (laravel) application's executable index.php located at: C:\Users\meusr\Workspace\www\myPHPproject\public\

And on one of my route: importer/run

I have:

$commandToRun = "npm start --prefix ". env('IMPORTER_PATH'). " /dev/null 2>&1";

Where IMPORTER_PATH is configured in my env, as: IMPORTER_PATH = C:\Users\meusr\Workspace\www\myproject\

when I try to execute the command with exec

exec($commandToRun, $output);

Page keeps on loading no output, no error and no end.

The script has no issue and running the same command on command line on windows system works:

npm start --prefix C:\Users\meusr\Workspace\www\myproject\

outputs as expected.

I thought it was issue with permission first (which should have thrown error, but I still tried and ran another command)

exec('npm -v', $output);

which outputs my npm version.

Similarly I tried to use simply node directImport.js which didn't work either.

Then tried to change directory to the location where node file is located and ran the command again. exec(cd C:\Users\meusr\Workspace\www\myproject\ && dir /dev/null 2>&1) // this works, but:

exec(cd C:\Users\meusr\Workspace\www\myproject\ && node directImport.js /dev/null 2>&1) // this didn't work

Thanks to miken32, what worked for me was:

<?php 
$commandString = 'start /b c:\\programToRun.exe -attachment "c:\\temp\file1.txt"'; 
pclose(popen($commandString, 'r')); 
?>

http://php.net/manual/en/function.popen.php#92413