如何在php中打开终端窗口 [英] How to open a terminal window in php

查看:150
本文介绍了如何在php中打开终端窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从.log文件中提取一些数据.我正在用awk做到这一点,并且工作正常-但现在我想将awk结果保存到变量中.我需要通过php打开终端窗口,并执行以下命令以获取所需信息:

I need to extract some data form a .log file. I'm doing this with awk and it works fine - but now I want to save awk results into a variable. I need to open a terminal window via php and do this command in order to get what I need:

cat apache_access.log | awk '{print $1}'

但是我不知道该怎么做.谁能告诉我如何打开与php的连接以及如何将此命令的结果保存在变量中?

But I don't know how to do this. Can anybody tell me how to open a connection to php and how to save the result of this command in a variable?

推荐答案

请参考 exec 函数.

示例:

<?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
echo exec('whoami');
?>

这篇关于如何在php中打开终端窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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