2016-10-05 8 views
0

私はPowerShellスクリプトを実行するための基本的なフォームを作成しようとしています。私は周りを見回し、RobinはIISとPHPを使ってPowerShellスクリプトを実行するという素晴らしい解決策があります。 ソース:http://theboywonder.co.uk/2012/07/29/executing-powershell-using-php-and-iis/ 自分のコードでテストを実行しましたが、自分のPSスクリプトでパス変数を修正しました。PowerShellを送信する基本的なPHPフォーム

私は今、onclickがPSスクリプトを実行して結果を同じページに返すサブミット機能を持つちょうど基本的なフォームを作成しようとしています。

私は彼のサンプルからわずかに変更されたPHPコードです。

<?php 
// If there was no submit variable passed to the script (i.e. user has visited the page without clicking submit), display the form: 
if(!isset($_POST["submit"])) 
{ 
?> 
<form name="testForm" id="testForm" action="pstest4.php" method="post"> 
    <input type="submit" name="submit" id="submit" value="Do stuff" /> 
</form> 
<?php  
} 
// Else if submit was pressed, check if all of the required variables have a value: 
elseif((isset($_POST["submit"])) 
{ 
// Get the variables submitted by POST in order to pass them to the PowerShell script: 
// Path to the PowerShell script. Remember double backslashes: 
$psScriptPath = "\\\\appswebfront\\Scripts\\mock.ps1"; 

// Execute the PowerShell script, passing the parameters: 
$query = shell_exec("powershell -command $psScriptPath < NUL"); 
echo $query;  
} 
?> 

私はそれを実行して、私が取得:それは$ psScriptPathで始まり、ここで私のプレビューで

Parse error: syntax error, unexpected ';' in \\APPSWEBFRONT\INETPUB\wwwroot\pstest4.php on line 31

31行目です。

もちろん、私がセミコロンを削除した場合、それは単に次のものになるでしょう。unexpected $query' (T_VARIABLE)と言います。

どこかの構文が間違っていると確信していますが、私は純粋にPHPの初心者なので、どこが間違っているのか分かりません。

送信ボタンがクリック/ポストされていないときにフォームを表示するページが必要です。クリックすると、PSスクリプトが実行され、出力が同じページに戻ります。

助けてください。

答えて

0

あなたはこのラインにあまりにも多くの括弧elseif((isset($_POST["submit"]))

elseif(isset($_POST["submit"]))であるべきです。

お試しください。

関連する問題