如何在Windows批处理文件中获取返回值

如何在Windows批处理文件中获取返回值,windows,batch-file,gulp,Windows,Batch File,Gulp,在Windows批处理文件中,我需要返回值,即apkVerison编号。当我在命令行或批处理文件中运行gulp getVersion时,它可以正常工作。我想将版本号保存到批处理文件中的一个变量中 gulpfile.js: gulp.task('getVersion', function () { var data = require('./package.json') console.log('Version = ' + data.apkDependencies.ap

在Windows批处理文件中,我需要返回值,即apkVerison编号。当我在命令行或批处理文件中运行gulp getVersion时,它可以正常工作。我想将版本号保存到批处理文件中的一个变量中

gulpfile.js:
  gulp.task('getVersion', function () {
      var data = require('./package.json')
      console.log('Version = ' + data.apkDependencies.apkVersion)
      return data.apkDependencies.apkVersion;
    });

abc.bat:
    set x=gulp getVersion 
    echo %x%
批处理文件不工作。echo只是呼应“大口喝”而已


对不起,我应该在运行gulp时提到这是它的输出

gulp getVersion
[22:16:44] Using gulpfile ~\CareWheelsCorp\CareWheels\gulpfile.js
[22:16:44] Starting 'getVersion'...
Version = 9.1.13
[22:16:44] Finished 'getVersion' after 1.91 ms

正如您所看到的版本隐藏在里面,我需要9.1.13号,它工作得非常愉快-正如您所要求的那样,响应
x
的内容

如果要执行
x
的内容,需要

%x%
如果你想得到返回值,你需要

for /f "delims=" %%r in ('%x%') do set "return=%%r"
echo %return%
(假设可执行文件响应的结果来自
stdout


鉴于澄清

for /f "tokens=1*delims== " %%r in ('%x%') do if "%%r"=="Version" set "return=%%s"
echo %return%

抱歉,我应该在运行gulp时提到这是它的输出gulp getVersion[22:16:44],使用gulpfile~\CareWheelsCorp\CareWheels\gulpfile.js[22:16:44]启动“getVersion”。。。Version=9.1.13[22:16:44]在1.91毫秒后完成了“getVersion”,因为您可以看到版本隐藏在里面,我需要R 9.1.13号。请将此数据编辑到您的问题中,因为无法看到换行符的位置,从这份报税表中查询您希望使用的信息也不是那么容易。我已经编辑了我的原始问题,请查看。所以@Magoo谢谢你的回答,但它不起作用。对不起,我提供了不完整的信息。期待已久:)哇@Magoo你跑得非常快,而且很有效。谢谢。我完了!!