S
S
Sam Stay2015-03-09 01:37:48
PHP
Sam Stay, 2015-03-09 01:37:48

How to properly execute exec in php?

How to write such code correctly so that it is executed and the value is written to the variable?

$per = exec('hddtemp /dev/sda | awk \'{print $4}\' | cut -c 1-2');
echo $per;

I tried to escape slashes, the output is also empty.
If you run this command in the console, the output is similar to this:
[[email protected] ~]# hddtemp /dev/sda | awk '{print $4}' | cut -c 1-2
45

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
S
Sam Stay, 2015-03-09
@savenko_egor

Found the problem. Thanks for the tip Cyril Saksin The problem is that in the console I tried from the root, and the puff is executed from the user. Specified to the user the full path to hddtemp and the problem was solved.
Example:
$result = `/usr/sbin/hddtemp /dev/sdb | awk '{print $4}' | cut -c 1-2`;

K
Kirill Saksin, 2015-03-09
@saksmt

$result = `hddtemp /dev/sda | awk '{print $4}' | cut -c 1-2`;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question