0

I need to run node js command from my php file. I am using exec() to do this. Here is my script

<?php

$ret = exec("node -v", $out, $err);
echo print_r($out);
?>

Here I am getting return value 1. How to fix this?

3
  • Read the documentation on "exec" Commented Aug 10, 2018 at 6:32
  • 1
    Is node in the PATH for the user/process running PHP? (E.g. run print_r(getenv('PATH')) to check / compare to path you get when running which node on terminal) Commented Aug 10, 2018 at 12:04
  • $out contains ONLY STD_OUT, to see an err u shd run "/usr/bin/node foo.js 2>&1" Commented Jan 26, 2024 at 12:21

1 Answer 1

1

http://php.net/manual/de/function.exec.php

Short summary:

So 1 means "Miscellaneous errors", have you tried running the command in the shell to see what happens?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.