PHP不执行在Windows .bat文件 [英] PHP Not executing .bat file in windows

查看:567
本文介绍了PHP不执行在Windows .bat文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图执行Windows Server 2008上使用PHP的批处理文件。

I am trying to execute a batch file using PHP on Windows Server 2008.

该文件称为NEWDNS.bat和它的任务是写一个新进入保存在c DNS区域文件:\\ WINDOWS \\ SYSTEM32 \\ DNS - 区域文件被命名为motlocal.co.uk

The file is called NEWDNS.bat and its mission is to write a new entry into a DNS zone file stored in c:\windows\system32\dns - the zone file is named motlocal.co.uk.

下面是newdns.bat的内容

Here are the contents of newdns.bat

@echo off
cd windows\system32\dns\
dnscmd dsvr012345 /recordadd motlocal.co.uk mynewsubdomain A 88.208.200.221
dnscmd dsvr012345 /ZoneReload motlocal.co.uk


newdns.bat存储在调用它的服务器作为PHP页面放在同一目录下: -


newdns.bat is stored in the same directory on the server as the PHP page that calls it:-

下面是调用newdns.bat页面的内容(PHP页面被称为dnscreator.php)

Here's the contents of the page that calls newdns.bat (the php page is called dnscreator.php)

<?php
if(isset($_POST['submit']))
{
echo exec("cmd.exe /c newdns.bat");
echo "Done!";
} else {
// display the form
?>
<form action="" method="post">
<input type="submit" name="submit" value="DO IT!">
</form>
<?php
}
?>

当我双击从Windows文件夹中的批处理文件 - 运行和它完美地执行其命令,并会在DNS区域文件中的新的子域

When I double click on the batch file from a windows folder - it runs and it executes its commands perfectly and creates the new subdomain in the dns zone file.

然而 - 不管我如何努力(我一直在这2天现在)当我运行dnscreator.php它它不会EXECUT

However - no matter how I try (and I have been on this for 2 days now) it it will NOT execut when I run dnscreator.php.

形式执行并显示消息完成!但在newdns.bat的命令未被执行。我知道这个批处理文件的工作,因为正如我说 - 我可以从Windows文件夹(双击)运行它,它做什么,它应该做的。

The form executes and displays the message "Done!" but the commands in the newdns.bat have not been carried out. I know the batch file works because as I said - I can run it from a windows folder (Double Click) and it does what its supposed to do.

在PHP安全模式关闭,以防万一你想知道,我已经试过了批处理文件移动到C:\\ Windows \\ System32下,这也不能工作。

PHP Safe mode is OFF, just in case you were wondering and I have tried moving the batch file into c:\windows\system32 and this didn't work either.

任何帮助/咨询/指针可以给大大AP preciated - 我在我无计可施!非常感谢。

Any help / advice / pointers you can give is greatly appreciated - I am at my wits end! Many Thanks.

推荐答案

1 - CD WINDOWS \\ SYSTEM32 \\ DNS \\ 从那里CD?它是从过程中调用批处理文件,当前目录的相对路径

1 - cd windows\system32\dns\ CD from where? it is a relative path from the current directory of the process calling the batch file

2 - 您可以运行该批处理文件,但是,可以在帐户(在其下运行Web服务器)做

2 - You can run the batch file, but, can the account (under which the web server is running) do it?

3 - 你怎么知道该批处理文件运行与否?尝试从批处理文件中留下记录(呼应里面分批GT;%temp%\\ batchphp.log

3 - How do you know the batch file is running or not? Try to leave a log from inside the batch file ( echo inside batch > "%temp%\batchphp.log")

这篇关于PHP不执行在Windows .bat文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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