中国DOS联盟

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

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

中国DOS联盟论坛
现在时间是 2026-08-09 16:58
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » P运行的一个问题 查看 783 回复 3
楼 主 P运行的一个问题 发表于 2008-09-06 02:49 ·  中国 云南 昆明 电信
中级用户
★★
积分 220
发帖 99
注册 2008-06-26 15:12
18年会员
UID 120818
性别 男
状态 离线
代码如下:
@echo off
set ur=%0
for /f %%i in ('type "%ur:~0,-9%\url.txt"') do set n=%%i
echo %n%
pause <-------------这里加上暂停

问题就出在暂停这了,为什么我在cmd里执行这个P处理没问题,并能显示url里的内容.且还会提示暂停.
而当我双击直接运行这个P的时候就一闪而过了?我加了pause怎么还能一闪就关闭了呢?代码我检查了好遍应该是没问题的啊.难道是%0在作怪?

[ Last edited by 23112656 on 2008-9-6 at 02:51 AM ]
2 发表于 2008-09-06 10:42 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
%0代表的是批处理文件本身,而不是批处理所在目录
"%ur:~0,-9%\url.txt"这个路径肯定是不存在的
3 发表于 2008-09-06 17:25 ·  中国 云南 昆明 电信
中级用户
★★
积分 220
发帖 99
注册 2008-06-26 15:12
18年会员
UID 120818
性别 男
状态 离线
可以我在cmd里执行这个P处理没问题,并能显示url里的内容呀.我刚把ur的值改为%cd%就不会双击后跳过了.但还是搞不懂%0应该可以打印出自身和自身包括的路径的啊,所以用:~0,-9去掉自身的名字只留下路径名+当前目录下的url.txt
可是还是一闪而过了...
4 发表于 2008-09-06 18:15 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
再仔细看看for的帮助
In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:

%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only

%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string

The modifiers can be combined to get compound results:

%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line

In the above examples %I and PATH can be replaced by other valid
values. The %~ syntax is terminated by a valid FOR variable name.
Picking upper case variable names like %I makes it more readable and
avoids confusion with the modifiers, which are not case sensitive.
论坛跳转: