[英]How to check if a shell command is running from PHP
EDIT: I have this but still not working;编辑:我有这个但仍然无法正常工作; I am trying to get this to check to see if that command is running.
我正在尝试使用它来检查该命令是否正在运行。 Thanks
谢谢
function command_exist($cmd) {
$return = shell_exec(sprintf("which %s", escapeshellarg($cmd)));
return !empty($return);
}
if (!command_exist('rtmpdump')) {
print 'doesnt exist';
} else {
echo ' exists ';
}
On Linux/Mac在 Linux/Mac 上
function command_exist($cmd) {
$return = shell_exec(sprintf("which %s", escapeshellarg($cmd)));
return !empty($return);
}
if (!command_exist('rtmpdump')) {
print 'doesnt exist';
} else {
shell_exec('rtmpdump');
}else {
echo ' exists ';
}
I can suggested, you could simply use:我可以建议,你可以简单地使用:
if (`which rtmpdump`) {
shell_exec('rtmpdump');
}
<?php
function command_exist($cmd) {
$return = shell_exec(sprintf("ps -ef | grep " . escapeshellarg($cmd) . " | grep -v grep"));
return !empty($return);
}
$command = 'command here';
if (!command_exist($command)) {
print 'not running';
} else {
echo ' running ';
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.