0

I want to run npm-like commands with Symfony's Component Process. The actual command is relaxed htmlFile.html. The command works when I run it with CLI, but when I run it with Process I get the error below.

The command "node -v" failed. Exit Code: 1(General error) Working directory: C:\xampp\pro-resume\public Output: ================ Error Output: ================ 'node' is not recognized as an internal or external command, operable program or batch file.

I'm using a library called relaxed.js to convert HTML files to PDF.

In this example, I tried to run node -v.

$process = new Process(['node', '-v']);
$process->mustRun();
echo $process->getOutput();

if (!$process->isSuccessful()) {
   throw new ProcessFailedException($process);
}

The env is Xampp server on Windows. Laravel 9, php 8.

gp_sflover
  • 3,460
  • 5
  • 38
  • 48
  • Looks like Node isn't installed globally, try in terminal `which node` to get the path then add it, for example `new Process(['/usr/path/node', '-v'])`. Or make Node global.. – Bossman Jun 21 '22 at 21:07
  • You can also use the `$process->setWorkingDirectory('/you_dir');` method to set the working directory where your commands will be executed – emrdev Jun 22 '22 at 08:36
  • @HarveyDent thanks, I'll try setting the directory, seems like it is looking for node in the public directory. – Ismayil Mirzayev Jun 22 '22 at 17:35
  • @HarveyDent not sure where should I set the working directory, currently it's public, but where should I run node? – Ismayil Mirzayev Jun 22 '22 at 17:57

0 Answers0