将命令的输出设置为变量 [英] Set output of a command to a variable

查看:76
本文介绍了将命令的输出设置为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取一个变量在10天之前修改过的文件数. 我可以使用

I want to get the number of files modified before 10 days to a variable. I can get number of files using

forfiles /P "D:\files" /S /D -10  | find /c /v ""

但是当我尝试使用FOR将其分配给变量时,会出现错误. 我在FOR中使用的命令是

But when i try to assign it to a variable using FOR it gives error. Command I used in FOR is

FOR /F "delims=" %i IN ('forfiles /P "D:\files" /S /D -10  | find /c /v ""') DO set today=%i

当我删除| find /c /v ""

推荐答案

FOR /F "delims=" %i IN ('forfiles /P "D:\files" /S /D -10  ^| find /c /v ""') DO set today=%i

在这种情况下,您需要对管道进行转义.

in this case you need to escape the pipe.

这篇关于将命令的输出设置为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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