我正试图这样做:
shell_exec("powershell -File C:\inetpub\wwwroot\altirisinstall\startinstall.ps1 $computername > /dev/null &");
只要我删除它就可以正常工作:
/ dev / null&
但是,这会使网站暂停并等待脚本完成。当我有这个时,脚本永远不会运行。
我也尝试了这个,它也阻止了ps1的运行:
/ dev / null 2>& 1&
编辑: 我需要一种方法让我的php在Windows服务器上运行powershell脚本而不是等待响应。等待导致我的网站挂起并阻止用户运行新命令。我研究并找到了上述解决方案,但有人指出这些是针对Linux服务器的。是否有另一种方法来执行我的powershell脚本而不是等待响应?
EDIT2: 我现在无法启动powershell,sql命令运行良好,页面刷新,但powershell永远不会运行,这里是代码:
<?php
if(isset($_POST['Submit'])) {
$connectionInfo = array( "Database"=>"database", "UID"=>"username", "PWD"=>"password");
$conn = sqlsrv_connect( "server", $connectionInfo);
$params = array();
$username = $_SERVER['AUTH_USER'];
$computername = $_POST['CName'];
$time = date("m/d - g:i a");
$sql2 = "INSERT INTO dbo.Installs (Hostname, Status, Username, Time) VALUES (?, ?, ?, ?)";
$var = array($computername, "InProgress", $username, $time);
sqlsrv_query($conn, $sql2, $var);
sqlsrv_close($conn);
shell_exec("powershell.exe -File C:\inetpub\wwwroot\altirisinstall\startinstall.ps1 $computername");
sleep(5);
header("Refresh:0");
}
?>
答案 0 :(得分:0)
There is no solution for this problem. This is a security measure in IIS that I don't want to spend the time trying to go around. I have gone a different route for this, Thanks for all the help.