一个批处理文件,运行 一个控制台 exe,returns/prints 一个字符串到命令行,并把它们作为 .bat 中的参数?

Can a batch file, run a console exe that returns/prints a string to the command line and take them as a parameter in the .bat?

如何 I/can 我从批处理文件 运行 简单的控制台 exe returns/prints 一个由 4 个数字组成的字符串到命令。行并将它们作为 .bat?

中的参数
  • 假设 consoleapp 在一行上打印四个 space 分隔的数字:

    @echo off
    for /f "tokens=1-4" %%a in ('consoleapp') do (
        echo arg1: %%a, arg2: %%b, arg3: %%c, arg4: %%d
    )
    pause
    
  • 没有分隔符,只有 4 位数字:

    @echo off
    for /f %%a in ('consoleapp') do set digits=%%a
    set digit1=%digits:~0,1%
    set digit2=%digits:~1,1%
    set digit3=%digits:~2,1%
    set digit4=%digits:~3,1%
    echo arg1: %digit1%, arg2: %digit2%, arg3: %digit3%, arg4: %digit4%
    pause