PHP +命令行执行
我正在尝试从命令行使用 PHP 运行 .bat 文件。我使用的是 Windows Vista 家庭高级版。
当我在 ipconfig.exe 这样的文件上使用脚本时,我会得到输出。但是,当我运行 .bat 文件时,它会提供文件中内容的输出,但不会执行它。
下面的内容可以工作并给我输出:
$runCommand = "C:\\WINDOWS\\system32\\ipconfig.exe";
$WshShell = new COM("WScript.Shell");
$output = $WshShell->Exec($runCommand)->StdOut->ReadAll;
echo "<p>$output</p>";
但这不行:
$runCommand = "C:\\Temp\\foo.bat";
$WshShell = new COM("WScript.Shell");
$output = $WshShell->Exec($runCommand)->StdOut->ReadAll;
echo "<p>$output</p>";
这是我的 foo.bat 文件中的内容:
C:/windows/system32/schtasks.exe /create /tn "TestTask" /tr "C:/Temp/configure.php" /sc minute /st 08:00:00
如果我复制此内容并粘贴到我的 Windows 命令行中,则该命令将成功执行。
不知道发生了什么事。请协助。
I'm trying to run a .bat file using PHP from the command-line. I'm using Windows Vista Home Premium.
When I use the script on a file like ipconfig.exe, I get the output. However, when I run the .bat file, it gives me output of what is in the file but it doesn't execute it.
What is below works and give me output:
$runCommand = "C:\\WINDOWS\\system32\\ipconfig.exe";
$WshShell = new COM("WScript.Shell");
$output = $WshShell->Exec($runCommand)->StdOut->ReadAll;
echo "<p>$output</p>";
But this doesn't:
$runCommand = "C:\\Temp\\foo.bat";
$WshShell = new COM("WScript.Shell");
$output = $WshShell->Exec($runCommand)->StdOut->ReadAll;
echo "<p>$output</p>";
Here's what's in my foo.bat file:
C:/windows/system32/schtasks.exe /create /tn "TestTask" /tr "C:/Temp/configure.php" /sc minute /st 08:00:00
If I copy this and paste in my Windows Command Line, this command executes successfully.
Not sure what is going on. Kindly assist.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为 bat 文件是提示命令的排队列表。尝试以下命令:
cmd /c myfile.bat
(也可能是/k,忘记执行和关闭哪个)
此外,复制如何从 PHP 运行 .bat 文件?
编辑
That's because a bat file is a queued list of commands for a prompt. Try the following:
cmd /c myfile.bat
(it may be /k too, forget which executes and closes)
Also, duplicate of How do you run a .bat file from PHP?
EDIT