2

I have this function:

exec("sudo /root/modbus/writeForceReg 2 0");

located in a php script. When I execute the script in terminal, it returns either 1 or -1 in the terminal window. My question is how to capture and store these two values in a variable in the same php script?

1

1 Answer 1

1

exec provides a second parameter which can be used to get the output of the process

exec("sudo /root/modbus/writeForceReg 2 0", $output);

If the application is using the stderr instead of stdout you need to use proc_open: http://php.net/manual/en/function.proc-open.php

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.