2011-08-30 4 views
0

Voici que je peux courir dans l'invite de commande sans problème:Exécution d'un script Powershell de PHP

powershell -noexit "& ""C:\wamp\www\mypowersher.ps1”"" 

Mais je veux ajouter à mon script PHP. C'est possible? J'ai essayé d'utiliser exec mais cela n'a pas fonctionné.

$psPath ='"C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"'; 
    $psDIR = 'C:\\wamp\\www\\mypowersher.ps1'; 
    $psScript = 'mypowersher.ps1'; 
    $runScript = $psDIR. $psScript; 
    $runCMD = $psPath." "& ".$runScript." 2>&1""; 

exec($runCMD); 
+3

Qu'avez-vous mis en "exec"? –

+2

Définir "ne fonctionne pas" – Mike

+0

$ psPath = '"C: \\ WINDOWS \\ system32 \\ WindowsPowerShell \\ v1.0 \\ powershell.exe"'; $ psDIR = 'C: \\ wamp \\ www \\ mypowersher.ps1'; $ psScript = 'mypowersher.ps1'; $ runScript = $ psDIR. $ psScript; $ runCMD = $ psPath. "" & ". $ RunScript." 2> &1""; exec ($ runCMD); – Dante

Répondre

1

Je pense que c'est peut-être un problème de configuration car votre description n'est pas claire. Alors essayez de tourner safe_mode= on sur votre serveur WAMP.

De plus, vous pouvez essayer system() s'il y a des différences.

+0

Merci d'avoir activé safe_mode = on pour résoudre le problème – Dante

0
Try it this way 

$psPath = '"C:\\Windows\\System32\WindowsPowerShell\v1.0\\powershell.exe"'; 
$psDIR = "C:\\wamp\\www\\"; 
$psScript = "mypower.ps1"; 
$runScript = $psDIR. $psScript; 
$runCMD = $psPath." ".$runScript." 2>&1"; 

exec($runCMD,$out,$ret); 


$output= shell_exec($runCMD); 
echo('<pre>'); 
echo($output); 
echo('</pre>'); 
Questions connexes