使用wget调用URL,并根据URL的内容返回ERRORLEVEL [英] Call URL with wget and return an ERRORLEVEL depending on URL's contents

查看:295
本文介绍了使用wget调用URL,并根据URL的内容返回ERRORLEVEL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

客户端具有基于Windows的内部服务器,在其上编辑CMS的内容。数据与实时Web服务器每夜同步。这是缓慢的互联网连接的解决方法。

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.

有两个事情要同步:新文件(已排序)和一个mySQL数据库。为此,我编写一个脚本,使用 mysqldump 将数据库导出到转储文件,并上传转储。

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.

上传过程使用第三方工具完成,名为 ScriptFTP ,一个FTP自动化工具。

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

然后我需要在目标服务器上运行基于PHP的导入脚本。根据此脚本的返回值,ScriptFTP操作继续,并重命名一些目录。

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.

我需要一个外部工具,因为scriptFTP只支持FTP调用。我在思考Windows版本的 wget

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

在scriptFTP中,我可以执行任何批处理或exe文件,但我只能解析 errorlevel ,而不是 stdout 输出。这意味着如果PHP导入操作出错,我需要返回 errorlevel 1 ,如果它很好,我需要返回 errorlevel 0 。此外,显然,如果无法连接导入脚本,我需要返回一个正错误。

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.

我完全控制导入PHP脚本,

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.

如何运行wget(或任何其他工具)启动服务器端导入),并根据PHP脚本返回的内容返回一定的错误级别。

我最好的打算是建立一个批次文件,将结果存储在文件中,批处理文件返回错误级别0或1,具体取决于文件的内容。但是我真的不知道如何使用批处理编程来匹配文件的内容。

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.

推荐答案

您可以在powershell中执行以下操作:

You can do the following in powershell:

$a = wget --quiet -O - www.google.com
$rc = $a.CompareTo("Your magic string")
exit $rc

这篇关于使用wget调用URL,并根据URL的内容返回ERRORLEVEL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆