I am using PowerShell to run a script that executes wget
to fetch a web page (a simple database import script) and analyzes its output (Error message or "OK").
I am using code from the answer to this previous question of mine.
$a = c:\path_to_wget\wget.exe --quiet -O - "http://www.example.com/import_db"
$rc = $a.CompareTo("OK")
exit $rc
When the result of the wget operation is a 404 - and wget probably returns an errorlevel 1 or 127 - I get the following error message from PowerShell:
You cannot call a method on a null-valued expression.
this obviously refers to my calling the CompareTo()
function.
However, wget gets executed and outputs something.
I am suspecting that wget outputs to the error console in this case, and this does not get caught by my $a operation.
How can I redirect the error output so that it gets caught by my script?
Boy, I'm sure going to be question king in the PowerShell tag this month! :)