Board logo

标题: [文件操作] [已解决]求助批处理怎样把多条命令的返回结果输出到文本不换行? [打印本页]

作者: habulu    时间: 2015-3-1 00:19     标题: [已解决]求助批处理怎样把多条命令的返回结果输出到文本不换行?

本帖最后由 pcl_test 于 2017-3-31 17:42 编辑

比如这两个命令(命令可能不同)
  1. wmic datafile where "drive='c:' and path='\\Windows\\' and filename='notepad'" get filename,size | find "notepad" >c:\1.txt
  2. wmic datafile where "drive='c:' and path='\\Windows\\' and filename='notepad'" get filename,size | find "notepad" >>c:\1.txt
复制代码
想让他们不换行,用下面的命令,可是没输出
  1. @echo off  
  2. for /f "tokens=*" %%i in ('wmic datafile where "drive='c:' and path='\\Windows\\' and filename='notepad'" get filename,size | find "notepad"') do ((set/p="%%i"<nul)>>"c:\1.txt")
  3. pause
复制代码
请教有没什么办法让多条命令的输出不换行
作者: pcl_test    时间: 2015-3-1 11:30

回复 1# habulu
两个例子参考下
  1. @echo off
  2. for /f "delims=" %%i in ('echo 125 ^&^& ver ^&^& echo 345') do set /p=%%i<nul
  3. pause
复制代码
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set s=
  4. for /f "tokens=1-2" %%i in ('wmic datafile where "drive='c:' and path='\\Windows\\' and filename='notepad'" get filename^,size ^| find "notepad" ^&^& wmic datafile where "drive='c:' and path='\\Windows\\' and filename='regedit'" get filename^,size ^| find "regedit"') do set "s=!s!%%i %%j "
  5. >1.txt echo !s!
  6. pause
复制代码

作者: habulu    时间: 2015-3-1 20:59

可以了  非常感谢




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2