中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-06-25 05:10
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 如何控制屏幕输出,使其左对齐或右对齐。 查看 1,821 回复 10
楼 主 如何控制屏幕输出,使其左对齐或右对齐。 发表于 2007-08-03 17:01 ·  中国 陕西 西安 电信
初级用户
积分 106
发帖 44
注册 2007-06-01 22:25
19年会员
UID 90001
性别 男
状态 离线
有位朋友想查询进程的具体文件路径,所以写了以下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
2 发表于 2007-08-03 17:19 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
积分 2,725
发帖 1,160
注册 2006-09-23 12:00
19年会员
UID 63486
来自 河北廊坊
状态 离线
使用制表符,基本上可以使格式整齐。
也就是Tab键啊,@echo %%a :后面跟的就是按Tab键得到的空格

@echo off
for /f "skip=3 tokens=1 delims= " %%a in ('tasklist') do @echo %%a : %%~fa
pause
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
3 发表于 2007-08-03 17:55 ·  中国 陕西 西安 电信
初级用户
积分 106
发帖 44
注册 2007-06-01 22:25
19年会员
UID 90001
性别 男
状态 离线
只能算是基本对齐,因为第一列文件名的长度不一样,所以第二列还是实现不了左对齐。
4 发表于 2007-08-03 18:05 ·  中国 陕西 西安 电信
铂金会员
★★★★
积分 5,212
发帖 2,478
注册 2007-02-08 23:39
19年会员
UID 79003
性别 男
状态 离线
用2个制表符
5 发表于 2007-08-03 18:14 ·  中国 陕西 西安 电信
初级用户
积分 106
发帖 44
注册 2007-06-01 22:25
19年会员
UID 90001
性别 男
状态 离线
不错,两列各用一个制表符,可以实现右对齐。谢谢。
6 发表于 2007-08-03 18:23 ·  中国 陕西 西安 电信
初级用户
积分 106
发帖 44
注册 2007-06-01 22:25
19年会员
UID 90001
性别 男
状态 离线
突然发现自己犯了一个大错,用以下方法得到的路径根本就不是 进程真实的安装路径。
@echo off
for /f "skip=3 tokens=1 delims= " %%a in ('tasklist') do @echo %%a : %%~fa
pause

到底用什么方法才能得到进程的具体路径呢?
7 发表于 2007-08-03 18:35 ·  印度 马哈拉施特拉邦 孟买郊区县 腾讯云
荣誉版主
★★★
积分 2,013
发帖 718
注册 2006-02-18 07:07
20年会员
UID 50550
状态 离线
@echo off
for /f "tokens=* skip=1" %%i in ('wmic process get Caption^,ExecutablePath') do echo %%i
pause
goto :eof

XP,SP2,专业版下测试通过。
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
ccwan +5 2007-08-03 18:42
8 发表于 2007-08-03 18:41 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
积分 2,725
发帖 1,160
注册 2006-09-23 12:00
19年会员
UID 63486
来自 河北廊坊
状态 离线
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很有研究啊,以后还请多多指教。
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
9 发表于 2007-08-03 19:38 ·  中国 陕西 西安 电信
初级用户
积分 106
发帖 44
注册 2007-06-01 22:25
19年会员
UID 90001
性别 男
状态 离线
论坛的高人真多,心肠又热,有求必应。小弟对你们的羡慕和敬意犹如滔滔江水,连绵不绝。^_^,马屁拍多了,

[ Last edited by 1112yuhua on 2007-8-3 at 07:39 PM ]
10 发表于 2007-08-03 20:25 ·  中国 广东 佛山 顺德区 电信
初级用户
★★
积分 193
发帖 98
注册 2007-01-17 11:56
19年会员
UID 76803
性别 男
状态 离线
wmic...一直是个大难题。。。找个时间好好密密。。今天算是大开眼界了
这家伙很聪明 什么都没留下
11 发表于 2010-12-13 20:57 ·  中国 江苏 苏州 电信
新手上路
积分 17
发帖 8
注册 2010-01-03 14:09
16年会员
UID 157870
性别 男
状态 离线
第七楼要的就是你找个效果为此找了很久(真的很久) 虽然说 直接用wmic process get caption,executablepath 或wmic process get caption,commandline也能实现
论坛跳转: