在php中运行Windows命令

在php中运行Windows命令

本文介绍了在php中运行Windows命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从php运行Windows命令行代码?我的Windows命令行代码是:

Is it possible to run windows command line code from php ?My windows command line code is:

<?php
error_reporting(E_ALL);
try {

echo exec('C:\xampp\mysql\bin>mysqlbinlog --start-datetime="2011-04-21 10:31:44" c:\xampp\mysql\data\binlog\bin-log.000001 > c:\xampp\mysql\data\binlog\sql.txt');

} catch (Exception $e) {
echo $e->getMessage();
}

现在我想使用system()exec()等从PHP运行此代码.任何帮助表示赞赏.

Now I want to run this code from PHP using system() or exec() etc.any help appreciated.

推荐答案

如果您能够通过命令行而不是通过WAMP手动运行命令,则Apache Service用户将不需要运行该服务执行命令和二进制文件的权限(如果与GUI相关,则也不能与桌面进行交互).

If you are able to run your commands manually from the command-line, but not via WAMP, than the user the Apache Service runs as does not have the needed permissions to execute your commands and binaries (nor interact with the desktop if it is GUI related).

默认情况下,Apache服务在以下用户帐户下运行: nt Authority \ system

By default, Apache service run under user account: nt authority\system

按照以下步骤将其更改为您的自定义用户(具有管理权限的用户)

Change it to your custom user (user with administrative rights) by following below steps,

  1. 点击Windows + R,打开运行"
  2. 键入"services.msc",这将打开Windows服务列表
  3. 找到并选择您的apache服务并打开其属性
  4. 转到登录"标签,然后将帐户从本地系统"更改为另一个用户/帐户
  5. 重新启动您的Apache服务

快乐编码:-)

这篇关于在php中运行Windows命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 15:34