标题: 如何控制屏幕输出,使其左对齐或右对齐。
[打印本页]
作者: 1112yuhua
时间: 2007-8-3 17:01
标题: 如何控制屏幕输出,使其左对齐或右对齐。
有位朋友想查询进程的具体文件路径,所以写了以下p处理。
@echo off
for /f "skip=3 tokens=1 delims= " %%a in ('tasklist') do @echo %%a : %%~fa
pause
但是其输出很乱,有没有什么办法控制使其左对齐或右对齐呢 。输出如下:
System : C:\Documents and Settings\ChenYuhua\桌面\System
System : C:\Documents and Settings\ChenYuhua\桌面\System
smss.exe : C:\Documents and Settings\ChenYuhua\桌面\smss.exe
csrss.exe : C:\Documents and Settings\ChenYuhua\桌面\csrss.exe
winlogon.exe : C:\Documents and Settings\ChenYuhua\桌面\winlogon.exe
SERVICES.EXE : C:\Documents and Settings\ChenYuhua\桌面\SERVICES.EXE
LSASS.EXE : C:\Documents and Settings\ChenYuhua\桌面\LSASS.EXE
Ati2evxx.exe : C:\Documents and Settings\ChenYuhua\桌面\Ati2evxx.exe
SVCHOST.EXE : C:\Documents and Settings\ChenYuhua\桌面\SVCHOST.EXE
SVCHOST.EXE : C:\Documents and Settings\ChenYuhua\桌面\SVCHOST.EXE
SVCHOST.EXE : C:\Documents and Settings\ChenYuhua\桌面\SVCHOST.EXE
SVCHOST.EXE : C:\Documents and Settings\ChenYuhua\桌面\SVCHOST.EXE
SVCHOST.EXE : C:\Documents and Settings\ChenYuhua\桌面\SVCHOST.EXE
SPOOLSV.EXE : C:\Documents and Settings\ChenYuhua\桌面\SPOOLSV.EXE
avp.exe : C:\Documents and Settings\ChenYuhua\桌面\avp.exe
Ati2evxx.exe : C:\Documents and Settings\ChenYuhua\桌面\Ati2evxx.exe
EXPLORER.EXE : C:\Documents and Settings\ChenYuhua\桌面\EXPLORER.EXE
avp.exe : C:\Documents and Settings\ChenYuhua\桌面\avp.exe
alg.exe : C:\Documents and Settings\ChenYuhua\桌面\alg.exe
ctfmon.exe : C:\Documents and Settings\ChenYuhua\桌面\ctfmon.exe
Maxthon.exe : C:\Documents and Settings\ChenYuhua\桌面\Maxthon.exe
conime.exe : C:\Documents and Settings\ChenYuhua\桌面\conime.exe
notepad.exe : C:\Documents and Settings\ChenYuhua\桌面\notepad.exe
wmiprvse.exe : C:\Documents and Settings\ChenYuhua\桌面\wmiprvse.exe
cmd.exe : C:\Documents and Settings\ChenYuhua\桌面\cmd.exe
cmd.exe : C:\Documents and Settings\ChenYuhua\桌面\cmd.exe
tasklist.exe : C:\Documents and Settings\ChenYuhua\桌面\tasklist.exe
作者: ccwan
时间: 2007-8-3 17:19
使用制表符,基本上可以使格式整齐。
也就是Tab键啊,@echo %%a :后面跟的就是按Tab键得到的空格
@echo off
for /f "skip=3 tokens=1 delims= " %%a in ('tasklist') do @echo %%a : %%~fa
pause
作者: 1112yuhua
时间: 2007-8-3 17:55
只能算是基本对齐,因为第一列文件名的长度不一样,所以第二列还是实现不了左对齐。
作者: slore
时间: 2007-8-3 18:05
用2个制表符
作者: 1112yuhua
时间: 2007-8-3 18:14
不错,两列各用一个制表符,可以实现右对齐。谢谢。
作者: 1112yuhua
时间: 2007-8-3 18:23
突然发现自己犯了一个大错,用以下方法得到的路径根本就不是 进程真实的安装路径。
@echo off
for /f "skip=3 tokens=1 delims= " %%a in ('tasklist') do @echo %%a : %%~fa
pause
到底用什么方法才能得到进程的具体路径呢?
作者: 3742668
时间: 2007-8-3 18:35
@echo off
for /f "tokens=* skip=1" %%i in ('wmic process get Caption^,ExecutablePath') do echo %%i
pause
goto :eof
XP,SP2,专业版下测试通过。
作者: ccwan
时间: 2007-8-3 18:41
Originally posted by 3742668 at 2007-8-3 18:35:@echo off
for /f "tokens=* skip=1" %%i in ('wmic process get Caption^,ExecutablePath') do echo %%i
pause
goto :eof
XP,SP2,专业版下测试通过。
看来3742668版主对wmic很有研究啊,以后还请多多指教。
作者: 1112yuhua
时间: 2007-8-3 19:38
论坛的高人真多,心肠又热,有求必应。小弟对你们的羡慕和敬意犹如滔滔江水,连绵不绝。^_^,马屁拍多了,
[ Last edited by 1112yuhua on 2007-8-3 at 07:39 PM ]
作者: luowei14
时间: 2007-8-3 20:25
wmic...一直是个大难题。。。找个时间好好密密。。今天算是大开眼界了
作者: messen
时间: 2010-12-13 20:57
第七楼要的就是你找个效果为此找了很久(真的很久) 虽然说 直接用wmic process get caption,executablepath 或wmic process get caption,commandline也能实现