【问题标题】:Return cscript output to batch [duplicate]将cscript输出返回到批处理[重复]
【发布时间】:2017-04-26 14:58:51
【问题描述】:

我的批处理脚本通过使用带有 Javascript 语法的 CScript 来执行 HTTP 请求,就像在我的示例中一样。

使用this approach(也是seen here)和一些help on escaping我尝试了以下方法:

@if (@This==@IsBatch) @then
@echo off
rem **** batch zone *********************************************************
    setlocal enableextensions EnableDelayedExpansion

    set OWNPATH="%~dpnx0"

    if not "%~11"=="" (
        FOR /F "usebackq tokens=*" %%r in (`cscript //E:JScript %OWNPATH%`) DO SET RESULT=%%r
        ECHO %RESULT%
    )

    exit /b

@end
// **** JScript zone *****************************************************
// Instantiate the needed component to make url queries
var http = WScript.CreateObject('Msxml2.XMLHTTP.6.0');

// perform request
var requestURL = "http://myserver/api";

// Make the request 
http.open("GET", requestUrl, false);
http.send();

WScript.Echo(http.ResponseText);

// All done. Exit
WScript.Quit(0);

不幸的是,我收到一条消息“ECHO 已关闭”。而不是 %RESULT% 中的字符串。

脚本在 Windows 2008 R2 服务器上运行。

【问题讨论】:

标签: batch-file jscript wsh


【解决方案1】:

感谢@Stephan,它在使用时有效

echo !RESULT!

由于delayed expansion

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 2018-12-17
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    • 2013-03-11
    • 1970-01-01
    相关资源
    最近更新 更多