标题: 怎么把组合命令的结果,赋值给变量?
[打印本页]
作者: zts59
时间: 2007-3-21 04:31
标题: 怎么把组合命令的结果,赋值给变量?
怎么才不通过文件中转实现呢?
例如:
dir /a/s/b test.exe|find /i "test.exe"
把上述结果赋值给一个变量。
作者: zh159
时间: 2007-3-21 04:52
for /f "delims=" %%i in ('dir /a/s/b test.exe^|find /i "test.exe"') do set str=%%i
少了in
Last edited by zh159 on 2007-3-20 at 04:02 PM ]
作者: zts59
时间: 2007-3-21 04:57
谢谢了,加一个要求:
dir /a/s/b test.exe|find /i "test.exe"
对上面这个结果进行判断,如果FIND成功,则把结果赋值变量。如果FIND不成功,则不赋值。
作者: zh159
时间: 2007-3-21 05:05
for /f "delims=" %%i in ('dir/a/s/b test.exe^|find /i "test.exe" 2>nul') do set str=%%i
找不到不会赋值给str
用2>nul屏蔽错误输出显示
作者: zts59
时间: 2007-3-21 08:50
不错,谢谢哈,
那个 2>nul 是不是要改成 2^>nul ?
作者: zh159
时间: 2007-3-21 22:01
Originally posted by zts59 at 2007-3-20 19:50:
不错,谢谢哈,
那个 2>nul 是不是要改成 2^>nul ?
忘了,在()里要用,dir的也要加上
@echo off
for /f "delims=" %%i in ('dir/a/s/b test.exe 2^>nul^|find /i "test.exe" 2^>nul') do set str=%%i