views:

129

answers:

1

A client has a Windows based in-house server, on which they edit the contents of a CMS. The data are synchronized nightly with the live web server. This is a workaround for a slow Internet connection.

There are two things to be synchronized: New files (already sorted) and a mySQL database. To do this, I am writing a script that exports the database into a dump file using mysqldump, and uploads the dump.

The upload process is done using a 3rd party tool named ScriptFTP, an FTP automation tool.

I then need to run a PHP based import script on the target server. Depending on this script's return value, the ScriptFTP operation goes on, and some directories are renamed.

I need an external tool for this, as scriptFTP only supports FTP calls. I was thinking about the Windows version of wget.

Within scriptFTP, I can execute any batch or exe file, but I can only parse the errorlevel resulting from the call and not the stdout output. This means that I need to return errorlevel 1 if the PHP import operation goes wrong, and errorlevel 0 if it goes well. Additionally, obviously, I need to return a positive errorlevel if the connection to the import script could not be made at all.

I have total control over the importing PHP script, and can decide what it does on error: Output an error message, return a header, whatever.

How would you go about running wget (or any other tool to kick off the server side import) and returning a certain error level depending on what the PHP script returns?

My best bet right now is building a batch file that executes the wget command, stores the result in a file, and the batch file returning errorlevel 0 or 1 depending on the file's contents. But I don't really know how to match a file's contents using batch programming.

+2  A: 

You can do the following in powershell:

$a = wget --quiet -O - www.google.com
$rc = $a.CompareTo("Your magic string")
exit $rc
Am
In PowerShell you don't even need `wget`. Just use `System.Ne.WebClient` and its `DownloadString` method.
Joey
Brilliant, this works perfectly. Thank you very much. @Johannes Rössel: Thanks for that tip as well, I will look into it.
Pekka
I have a follow-up question here: http://stackoverflow.com/questions/2044011/powershell-script-cant-read-return-value-of-executed-program if anybody wants to take a look.
Pekka