doutangu4978 2012-06-20 00:53
浏览 75
已采纳

屏幕输出到PHP

I have a PHP file with shell commands running through a screen, the commands run fine but I was wondering if there was a way to get this to output to PHP without writing to another file and reading it on PHP's end.

PHP - trace() is just a fancy print_r()

$cmd = 'ls -h /';
trace(shell_exec('screen -S output -p 0 -X stuff "`echo '.$cmd.'\'
\'`"'));

Web output

NULL

Screen output

www-data@:/home/ubuntu$ ls -h /
bin   build  etc   initrd.img      lib         media  opt   root  selinux  sys  usr  vmlinuz
boot  dev    home  initrd.img.old  lost+found  mnt    proc  sbin  srv      tmp  var  vmlinuz.old

Any suggestions?

--Edit--

Certain commands aren't outputting directly, one of the reasons I'm using screen

PHP

$cmd = 's3ls';
trace(shell_exec('screen -S output -p 0 -X stuff "`echo '.$cmd.'\'
\'`"'));
trace(shell_exec($cmd));

Web output

trace:NULL
trace:NULL

Screen

www-data@:/home/ubuntu$ s3ls
+---------------+--------------------------+
|     Name      |       CreationDate       |
+---------------+--------------------------+
| bucket        | 2012-05-31T13:08:51.000Z |
| bucket        | 2012-01-17T16:51:58.000Z |
| bucket        | 2012-03-31T11:19:54.000Z |
+---------------+--------------------------+

展开全部

  • 写回答

1条回答 默认 最新

  • duanning9110 2012-06-20 21:53
    关注

    void passthru ( string $command [, int &$return_var ] )

    The passthru() function is similar to the exec() function in that it executes a command. This function should be used in place of exec() or system() when the output from the Unix command is binary data which needs to be passed directly back to the browser. A common use for this is to execute something like the pbmplus utilities that can output an image stream directly. By setting the Content-type to image/gif and then calling a pbmplus program to output a gif, you can create PHP scripts that output images directly.

    Though apparently it may be a bit flaky.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 MATLAB解决问题
  • ¥20 哪位专业人士知道这是什么原件吗?哪里可以买到?
  • ¥15 关于#c##的问题:treenode反序列化后获取不到上一节点和下一节点,Fullpath和Handle报错
  • ¥15 一部手机能否同时用不同的app进入不同的直播间?
  • ¥15 没输出运行不了什么问题
  • ¥20 输入import torch显示Intel MKL FATAL ERROR,系统驱动1%,: Cannot load mkl_intel_thread.dll.
  • ¥15 点云密度大则包围盒小
  • ¥15 nginx使用nfs进行服务器的数据共享
  • ¥15 C#i编程中so-ir-192编码的字符集转码UTF8问题
  • ¥15 51嵌入式入门按键小项目