doutangu4978
2012-06-20 08: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 |
+---------------+--------------------------+

图片转代码服务由CSDN问答提供 功能建议

我有一个PHP文件,其中shell命令在屏幕上运行,命令运行良好,但我想知道是否有 一种方法是将其输出到PHP而不写入另一个文件并在PHP结束时读取它。

PHP - trace()只是一个花哨的print_r()

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

Web输出

  NULL 
   
 
 

屏幕输出

  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 
   
 
 

有什么建议吗?

- 编辑 -

某些命令没有直接输出,这是我使用屏幕的原因之一

PHP

  $ cmd ='s3ls'; 
 \ trace(shell_exec('screen -S output -p 0  -  X stuff“`echo'。$ cmd。'\'
 
 \'`”')); 
 \ trace(shell_exec($ cmd)); 
   
 
 <  p> Web输出 
 
 
  trace:NULL 
trace:NULL 
   
 
 

Screen n

  www-data @:/ home / ubuntu $ s3ls 
 + --------------- + --------------  ------------ + \ N | 名称|  CreationDate | 
 + --------------- + -------------------------- + 
 | 斗|  2012-05-31T13:08:51.000Z | 
 | 斗|  2012-01-17T16:51:58.000Z | 
 | 斗|  2012-03-31T11:19:54.000Z | 
 + --------------- + ---------------------  ----- + 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanning9110 2012-06-21 05: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.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题