本文将带您了解关于phpshell_exec()输出来获取文本文件的新内容,同时我们还将为您解释php获取文件列表并输出的相关知识,另外,我们还将为您提供关于linuxexec和shell_exec函
本文将带您了解关于php shell_exec()输出来获取文本文件的新内容,同时我们还将为您解释php获取文件列表并输出的相关知识,另外,我们还将为您提供关于linux exec 和 shell_exec函数_PHP教程、npm安装不工作通过PHP系统()(exec / shell_exec)、PHP exec / shell_exec / system无法通过浏览器工作、php exec或shell_exec在脚本执行结束后不会终止它的进程的实用信息。
本文目录一览:- php shell_exec()输出来获取文本文件(php获取文件列表并输出)
- linux exec 和 shell_exec函数_PHP教程
- npm安装不工作通过PHP系统()(exec / shell_exec)
- PHP exec / shell_exec / system无法通过浏览器工作
- php exec或shell_exec在脚本执行结束后不会终止它的进程
php shell_exec()输出来获取文本文件(php获取文件列表并输出)
我正在尝试在我的Centos计算机上运行rate -c 192.168.122.0/24命令,并使用shell_exec(‘rate -c 192.168.122.0/24’)命令将该命令的输出写入文本文件;还是没有运气!!
解决方法:
如您忘记提及的那样,您的命令提供了一个非结束输出流.要实时读取输出,您需要使用popen.
来自PHP网站的示例:
$handle = popen('/path/to/executable 2>&1', 'r');
echo "'$handle'; " . gettype($handle) . "\n";
$read = fread($handle, 2096);
echo $read;
pclose($handle);
您可以像文件一样读取过程输出.
linux exec 和 shell_exec函数_PHP教程
popen,passthru,proc_open,shell_exec的返回结果如下:
[root@krlcgcms01 shell]# php test.php 1001.log 10.log 10.tar.gz aaa.tar.gz mytest test1101 test1102 weblog_2010_09 我能发现的就这几个函数,能执行
一般情况下,很少会用php去执行linux命令,不过特殊情况下,你也许会用到这些函数。以前我知道有二个函数可以执行linux命令,一个是exec,一个是shell_exec。其实有很多的,结合手册内容,介绍以下6个函数。
立即学习“PHP免费学习笔记(深入)”;
1,exec函数
返回结果如下:
[root@krlcgcms01 shell]# php ./exec.php array ( [0] => 1001.log [1] => 10.log [2] => 10.tar.gz [3] => aaa.tar.gz [4] => mytest [5] => test1101 [6] => test1102 [7] => weblog_2010_09 )
npm安装不工作通过PHP系统()(exec / shell_exec)
我使用npm install来安装gulp-sass和其他软件包。 这工作正常使用CLI(与sudo su锻造):
cd /path/to/package.json/ npm install
package.json看起来像:
{ "name": "skeleton","version": "1.0.0","authors": [ "Me <me@mycompany.co.uk>" ],"private": true,"devDependencies": { "gulp": "^3.8.11","gulp-autoprefixer": "^2.1.0","gulp-concat": "^2.5.2","gulp-minify-css": "^1.0.0","gulp-notify": "^2.2.0","gulp-sass": "^1.3.3","gulp-sourcemaps": "^1.5.2","gulp-uglify": "^1.2.0" },"dependencies": { "node-notifier": "^4.2.1","streamqueue": "^0.1.3" } }
在命令行使用PHP也可以正常工作:
PHP -r "system('npm install');"
但是通过Nginx / PHP-FPM运行下面的PHP:
curl:从CLI的每个文件附加头文件(用于多部分POST,SOAP等)
我如何从网上比较两个文件
Java Apache CLI OptionBuilder不能用作Builder模式
开始/ B不启动任务
PHP proc_open打开多次
<?PHP set_time_limit(0); chdir('/path/to/package.json/'); echo "<pre>"; echo shell_exec('npm install 2>&1'); die();
输出包含以下行的debugging文件:
81427 error Linux 4.5.5-x86_64-linode69 81428 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" 81429 error node v0.12.7 81430 error npm v2.11.3 81431 error file sh 81432 error path sh 81433 error code ELIFECYCLE 81434 error errno ENOENT 81435 error syscall spawn sh 81436 error node-sass@2.1.1 install: `node scripts/install.js` 81436 error spawn sh ENOENT 81437 error Failed at the node-sass@2.1.1 install script 'node scripts/install.js'. 81437 error This is most likely a problem with the node-sass package,81437 error not with npm itself. 81437 error Tell the author that this fails on your system: 81437 error node scripts/install.js 81437 error You can get their info via: 81437 error npm owner ls node-sass 81437 error There is likely additional logging output above.
我试图比较以下两种情况:
which npm
都返回'/ usr / local / bin / npm'
–
echo $USER
都返回'伪'
–
echo $GROUP
都返回''(空)
–
echo $PATH
CLI返回:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
PHP返回:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
–
which sh
都返回'/ bin / sh'
–
ps $$
CLI返回:
PID TTY STAT TIME COMMAND 13111 pts/2 S 0:00 bash
PHP返回:
PID TTY STAT TIME COMMAND 25759 ? S 0:00 sh -c ps $$
–
npm -v
都返回“2.11.3”
–
npm version
CLI返回:
{ skeleton: '1.0.0',npm: '2.11.3',http_parser: '2.3',modules: '14',node: '0.12.7',openssl: '1.0.1p',uv: '1.6.1',v8: '3.28.71.19',zlib: '1.2.8' }
PHP返回无骨架1.0.0:
{ npm: '2.11.3',zlib: '1.2.8' }
–
npm config ls -l
CLI返回:
; cli configs long = true user-agent = "npm/2.11.3 node/v0.12.7 linux x64" ; userconfig /home/forge/.npmrc ignore-scripts = false loglevel = "info" prefix = "/home/forge/npm" progress = false ; default values access = null always-auth = false bin-links = true browser = null ca = null cache = "/home/forge/.npm" cache-lock-retries = 10 cache-lock-stale = 60000 cache-lock-wait = 10000 cache-max = null cache-min = 10 cafile = undefined cert = null color = true depth = null description = true dev = false editor = "vi" engine-strict = false fetch-retries = 2 fetch-retry-factor = 10 fetch-retry-maxtimeout = 60000 fetch-retry-mintimeout = 10000 force = false git = "git" git-tag-version = true global = false globalconfig = "/home/forge/npm/etc/npmrc" globalignorefile = "/home/forge/npm/etc/npmignore" group = 1013 heading = "npm" https-proxy = null if-present = false ignore-scripts = false init-author-email = "" init-author-name = "" init-author-url = "" init-license = "ISC" init-module = "/home/forge/.npm-init.js" init-version = "1.0.0" json = false key = null link = false local-address = undefined ; loglevel = "warn" (overridden) ; long = false (overridden) message = "%s" node-version = "0.12.7" npat = false onload-script = null optional = true parseable = false ; prefix = "/usr/local" (overridden) production = false proprietary-attribs = true proxy = null rebuild-bundle = true registry = "https://registry.npmjs.org/" rollback = true save = false save-bundle = false save-dev = false save-exact = false save-optional = false save-prefix = "^" scope = "" searchexclude = null searchopts = "" searchsort = "name" shell = "/bin/bash" shrinkwrap = true sign-git-tag = false spin = true strict-ssl = true tag = "latest" tag-version-prefix = "v" tmp = "/tmp" umask = 2 unicode = true unsafe-perm = true usage = false user = 1013 ; user-agent = "npm/{npm-version} node/{node-version} {platform} {arch}" (overridden) userconfig = "/home/forge/.npmrc" version = false versions = false viewer = "man"
PHP返回:
; cli configs long = true user-agent = "npm/2.11.3 node/v0.12.7 linux x64" ; userconfig /home/forge/.npmrc ignore-scripts = false loglevel = "warn" prefix = "/home/forge/npm" progress = false ; default values access = null always-auth = false bin-links = true browser = null ca = null cache = "/home/forge/.npm" cache-lock-retries = 10 cache-lock-stale = 60000 cache-lock-wait = 10000 cache-max = null cache-min = 10 cafile = undefined cert = null color = true depth = null description = true dev = false editor = "vi" engine-strict = false fetch-retries = 2 fetch-retry-factor = 10 fetch-retry-maxtimeout = 60000 fetch-retry-mintimeout = 10000 force = false git = "git" git-tag-version = true global = false globalconfig = "/home/forge/npm/etc/npmrc" globalignorefile = "/home/forge/npm/etc/npmignore" group = 1000 heading = "npm" https-proxy = null if-present = false ignore-scripts = false init-author-email = "" init-author-name = "" init-author-url = "" init-license = "ISC" init-module = "/home/forge/.npm-init.js" init-version = "1.0.0" json = false key = null link = false local-address = undefined loglevel = "warn" ; long = false (overridden) message = "%s" node-version = "0.12.7" npat = false onload-script = null optional = true parseable = false ; prefix = "/usr/local" (overridden) production = false proprietary-attribs = true proxy = null rebuild-bundle = true registry = "https://registry.npmjs.org/" rollback = true save = false save-bundle = false save-dev = false save-exact = false save-optional = false save-prefix = "^" scope = "" searchexclude = null searchopts = "" searchsort = "name" shell = "bash" shrinkwrap = true sign-git-tag = false spin = true strict-ssl = true tag = "latest" tag-version-prefix = "v" tmp = "/tmp" umask = 18 unicode = true unsafe-perm = true usage = false user = 1000 ; user-agent = "npm/{npm-version} node/{node-version} {platform} {arch}" (overridden) userconfig = "/home/forge/.npmrc" version = false versions = false viewer = "man"
–
报告可能相关的configuration差异是:
- group (1013 / 1000) - shell (/bin/bash / bash) - I've tried using /bin/bash -c "npm install" but it seems to make no difference. - umask (2 / 18) - user (1013 / 1000) (user 1000 is "forge",user 1013 is myself)
我完全没有想法。 如果你有任何想法为什么引入Nginx / PHP-fpm导致这个问题,您的input将不胜感激。
非常感谢。
在命令行上通过windowsbatch file执行远程服务器的PHP脚本
不能执行exec命令(PHP / windows / ffmpeg)
带有空格的Apache CLI选项值
在多个文件上运行命令并保持相同的名称
如何解决InnoDB:无法locking./ibdata1 MysqL错误?
PHP exec / shell_exec / system无法通过浏览器工作
我正在运行一个带有apache版本1.3.33和PHP版本4.4的SCO Unix盒子.我可以通过cli正确执行exec命令,但是在尝试通过浏览器执行脚本时会遇到麻烦.我的设置是:
>安全模式关闭
>完全读/写/执行权限
>显示所有错误
>没有禁用功能
我的代码:htdocs目录中的test_script.PHP
<?PHP
exec('ls',$out,$rval);
echo "Output:<hr />";
print "<pre>"; print_r($out); print "</pre>";
echo "Return Value:<hr />";
echo $rval;
?>
我也尝试过显式设置可执行二进制路径.测试脚本与apache是相同的用户/组.我也尝试在arg中添加2>& 1,但看不到任何变化.先感谢您.
见here for similar.
解决方法:
尝试
$output = shell_exec('ls /tmp/ 2>&1')
您可能遇到运行网页的用户对当前目录的权限问题.
你也可以试试whoami命令.
php exec或shell_exec在脚本执行结束后不会终止它的进程
我正在尝试使用shell命令来检查PHP文件的语法错误,它在Windows(WAMP)中工作正常,但是在Linux上由shell命令exec / shell_exec / popen等创build的进程永远不会终止,从而导致apache挂起被我强行杀死。 杀死这个进程后也没有产生输出。
我的testing脚本是
文件test.PHP是示例一行PHP文件,只testing其中包含
<?PHP $test['arr'] = 'bla'; ?>
和我试图检查语法错误的代码是:
libdb4.6-dev与libdb4.7-dev
Linux使用boost asio拒绝套接字绑定的权限
如何在BusyBox上启用SSH而不重新编译BusyBox?
使用linux perf工具来每秒钟报告计数器,如vmstat
从套接字获取IP地址,端口和连接typesfd
$slash = file_get_contents('test.PHP'); $tmpfname = tempnam("tmp","PHPFile"); file_put_contents($tmpfname,$slash); exec("PHP -l ".$tmpfname." 2>&1",$error); //also tried shell_exec but same behavIoUr $errtext = ''; foreach($error as $errline) $errtext.='<br>'.$errline; unlink($tmpfname); echo $errtext;
也试过使用函数popen
$slash = file_get_contents('test.PHP'); $tmpfname = tempnam("tmp",$slash); $handle = popen("PHP -l ".$tmpfname." 2>&1",'r'); $errtext = fread($handle,2096); pclose($handle); unlink($tmpfname); echo $errtext;
请有人指出我在哪里做错了,为什么由shell命令创build的过程永远不会在Linux本身结束,我试图寻找很多关于这个问题,但我没有得到任何结果。
在32位模式和64位操作系统的64位模式下编译ioctl函数有什么不同?
Linux从设备本身运行的脚本中卸载一个设备
为什么我不能在Ubuntu中使用wget获取这个页面?
无限recursion别名`cd`
为500万次每日浏览量优化Nginx + PHP-FPM
我得到了阻塞问题的根本原因,这是在同一个用户的Linux服务器阻止所有其他请求的PHP会话(令人惊讶的是在Windows上工作良好)。
我用session_write_close(); 在运行exec和问题解决之前,但现在我有另外一个问题,这个脚本在Linux中,它被张贴在另一个问题PHP exec / shell_exec /系统/ popen / proc_open运行调用脚本本身无限次数在Linux上
我们今天的关于php shell_exec()输出来获取文本文件和php获取文件列表并输出的分享已经告一段落,感谢您的关注,如果您想了解更多关于linux exec 和 shell_exec函数_PHP教程、npm安装不工作通过PHP系统()(exec / shell_exec)、PHP exec / shell_exec / system无法通过浏览器工作、php exec或shell_exec在脚本执行结束后不会终止它的进程的相关信息,请在本站查询。
本文标签: