Мне нужно использовать скрипт powershell в моем PHP-коде. Код Javascript вызывает файл PHP и ожидает ответа, код PHP вызывает мой скрипт powershell и возвращает значение. Это прекрасно работает, когда я запускаю только PHP, который вызывает скрипт powershell. Это также прекрасно работает, когда я просто печатаю значение в команде runpm.php commenting shell_exec (). Поэтому я предполагаю, что проблема в команде Shell_exec (). Любая помощь могла бы быть полезна. Заранее спасибо.
код JavaScript:
var myLink = document.getElementById('btn');
var php_var = "<?php echo $dest_path; ?>";
myLink.onclick = function(){
try{
var pingtext = document.getElementById('ping');
var ping = document.getElementById('btn');
ping.style.backgroundColor = "#5bc0de";
ping.style.visibility='hidden';
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (this.responseText == 1) {
alert(this.responseText);
ping.style.visibility='visible';
ping.style.backgroundColor = "green";
ping.innerHTML='Import Success' ;
ping.style.width='80px';
ping.style.marginLeft='10%';
pingtext.innerHTML = '';
} else {
alert("error");
ping.style.visibility='visible';
ping.style.display='block';
ping.style.backgroundColor = "red";
ping.innerHTML='Failed' ;
ping.style.width='80px';
ping.style.marginLeft='25%';
pingtext.innerHTML = '';
}
}
};
pingtext.innerHTML = "<img src=\"gentel/production/images/loadingspinner.gif\" width=\"30px\">";
xmlhttp.open("Get", "runpm.php", true);
xmlhttp.send();
}catch(e){
console.error(e);
}
runpm.php:
<?php
$psoutput = shell_exec('powershell -ExecutionPolicy Bypass -NoProfile -File "C:\inetpub\wwwroot\retailPlanning\testpsscript.ps1"');
echo "$psoutput"
?>
testpsscript.ps1:
cls
echo "1"