0

The following I can run in the command Prompt with no problem:

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

But I want to add it to my PHP script. Is it possible? I tried using exec but it did not work.

    $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);
2
  • $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); Commented Aug 30, 2011 at 4:37
  • @user874339 please edit your question rather than posting a comment. Commented Aug 30, 2011 at 4:59

2 Answers 2

1

I think it's possibly a problem with configuration since your description is unclear. So try turning safe_mode= on on your WAMP server.

Additionally you can try system() if it makes any differences.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks turning safe_mode= on fix the problem
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>' );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.