[英]How to check if a shell command is running from PHP
编辑:我有这个但仍然无法正常工作; 我正在尝试使用它来检查该命令是否正在运行。 谢谢
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 ';
}
在 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 ';
}
我可以建议,你可以简单地使用:
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.