I have a powershell script that restarts the Apache Web server on my machine. The script works fine, but the log reports an error. The error seems to be coming from Powershell, not Apache, since if I just do a
.\httpd.exe -k config
I get no errors, and the first like
.\http.exe -k restart
does not give an errors either. (note: Powershell complains on line #11, not #10 the first invoke of httpd.exe). I am using powershell V4, on Windows 7.
So I want to understand what Powershell is doing here, since I think that Apache is working fine.
Here is the script:
# This PowerShell script restarts apache
start-transcript -Path install.log -Append
Write-Host "apache.ps1 Script`r`n"
$sixtyfour = [Environment]::Is64BitProcess
$exe = "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin\httpd.exe"
Write-Host "64-Bit Powershell: "$sixtyfour
& $exe -k restart *>> install.log
Write-Host ""
& $exe -k config *>> install.log
Here is the log:
httpd.exe : Reconfiguring the Apache2.2 service
At G:\wwwroot\setup\apache.ps1:11 char:1
+ & $exe -k config *>> install.log
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Reconfiguring the Apache2.2 service:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
The Apache2.2 service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.
Just found out about redirecting errors to strings. See answer #2 at:
Error when calling 3rd party executable from Powershell when using an IDE
which points you to:
$LastExitCode=0 but $?=False in PowerShell. Redirecting stderr to stdout gives NativeCommandError