我如何在Windows变量的命令的结果? [英] How do I get the result of a command in a variable in windows?

查看:155
本文介绍了我如何在Windows变量的命令的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待得到一个命令的结果为Windows批处理脚本变量(见<一href=\"http://stackoverflow.com/questions/58207/using-the-result-of-a-command-as-an-argument-in-bash#58214\">how获得在脚本相当于bash的bash的一个命令的结果)。将在.bat文件工作方案是preferred,但其他常见的Windows脚本解决方案也欢迎。

I'm looking to get the result of a command as a variable in a Windows batch script (see how to get the result of a command in bash for the bash scripting equivalent). A solution that will work in a .bat file is preferred, but other common windows scripting solutions are also welcome.

推荐答案

如果你要捕获所有的命令输出,您可以使用批处理这样的:

If you have to capture all the command output you can use a batch like this:

@ECHO OFF
IF NOT "%1"=="" GOTO ADDV
SET VAR=
FOR /F %%I IN ('DIR *.TXT /B /O:D') DO CALL %0 %%I
SET VAR
GOTO END

:ADDV
SET VAR=%VAR%!%1

:END

所有的输出线都存储在VAR与分离!

All output lines are stored in VAR separated with "!".

@约翰:是对此有任何实际用途?我想你应该看的PowerShell或能够轻松地执行脚本任务其他编程语言(Python和Perl中,PHP和Ruby)

@John: is there any practical use for this? I think you should watch PowerShell or any other programming language capable to perform scripting tasks easily (Python, Perl, PHP, Ruby)

这篇关于我如何在Windows变量的命令的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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