从控制台命令输出运行通过php获取切割 [英] Output from console commands run thru php get cutted

查看:177
本文介绍了从控制台命令输出运行通过php获取切割的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我通过putty在控制台中运行 ps ax 命令时,我获得:

When I run ps ax command in console via putty I get:

1053  ??  Ss     0:45.47 /usr/local/sbin/nrpe2 -d -c /usr/local/etc/nrpe.cfg
1085  ??  Is     0:00.03 /bin/sh /usr/local/bin/mysqld_safe --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --pid-file=/var/db/mysql/MYNAME.pid

但是当我运行这个命令via php:

But when I run this command via php:

exec('ps ax', $o);
print_r($o);

我得到了,但 cutted

[27] =>  1053  ??  Ss     0:45.48 /usr/local/sbin/nrpe2 -d -c /usr/local/etc/nrpe.cfg
[28] =>  1085  ??  Is     0:00.03 /bin/sh /usr/local/bin/mysqld_safe --defaults-extra-f

为什么从位置> = 79截取的所有字符都被截断?

Why are all characters from position >=79 truncated?

推荐答案

这里是我们在脚本中使用的技术:

Here's the technique we used on our script:

exec("export COLUMNS=1000; ps ax | grep $parameter", $results);

这是COLUMNS的含义

COLUMNS
   Used by the select builtin command to determine the terminal width when 
   printing selection lists. Automatically set upon receipt of a SIGWINCH. 

这篇关于从控制台命令输出运行通过php获取切割的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆