2012-10-10 3 views
0

shell_exec를 사용하여 PHP를 실행하는 powershell 스크립트가 있으며 Ajax 호출이있을 때이 파일을 실행합니다. (codeigniter 2 환경을 사용하고 있습니다)PHP - Shell Exec - Powershell and Ajax

ps 파일을 실행하는 데 약 45 초가 걸리기 때문에 Ajax를 호출하므로 Ajax를 통해이를 수행 할 것이라고 생각하여 사용자에게 메시지를 보낼 수 있다고 생각했습니다. 로드 중입니다.

내 아약스 기능은 다음과 같습니다 :

<script> 
    $(document).ready(function() { 
     $.fn.colorbox({href:"#inline_content", inline:true, width:"650px", height:"235px", overlayClose: false, showClose: false}); 
     $('#cboxClose').remove(); 

     var csrf = $('[name="csrf_test_name"]').val(); 

     $.ajax({ 
      type: "POST", 
      url: "/index.php/ajax/addAccount", 
      data: { 
        csrf_test_name: csrf 
        }, 
      cache:false, 
      success: 
       function(data){ 
        if(data == "True"){ 
         window.location = "/index.php/private"; 
        }else{ 
         $(window).colorbox.close(); 
         alert("There was a problem creating your account."); 
        } 
       }, 
      error: function (xhr, ajaxOptions, thrownError) { 
        alert(xhr.status); 
        alert(thrownError); 
        $('#Loading').hide(); 
        } 

     }); 


    }); 
</script> 

CI를 아약스 컨트롤러는 단지 모델에 공급하는 데이터를 잡는다.

쉘 간부 기능은 다음과 같습니다 :

function createCompany($companyID, $companyName, $domain){ 

    $psCompanyName = "t_".$companyID. "_".str_replace(" ", "", $companyName); 

    $psScriptPath = "c:\\inetpub\\powershellscripts\\createCompany.ps1"; 
    $ps = shell_exec("powershell -command $psScriptPath -companyName '".$psCompanyName."' -domain '".$domain."'"); 
    return $ps; 

} 

PS1 파일이 잘 실행합니다. $ ps는 "True"또는 "False"값을 포함해야합니다 (ps1은 쓰기 출력이 "True"이거나 쓰기 출력이 "False"로 끝나고 모든 작업이 성공적으로 실행되었고 모든 작업이 성공적으로 실행되었습니다.)

return $ ps를 return "True"로 바꾸거나 "False"를 반환하면 sucess : 섹션이 잘 작동합니다 (오류로부터도 아무 것도 얻지 못함). 또한 Ajax 외부에서 함수를 실행할 때 얻을 수 있습니다. ..? 아약스가 시간 초과되기 때문에 결과

이이 스크립트를 실행 한 고정

답변

1

겠습니까하지만이 셸 간부 코드를 변경하는 데 필요한 :

$ps = shell_exec("powershell -command $psScriptPath -companyName '".$psCompanyName."' -domain '".$domain."' < Nul"); 

Nul 비트는 무엇이 있는지 모르지만 powershell을 실행 중이지만 오류가 발생했습니다. 500