|
Scott0902
中级用户
  
积分 466
发帖 237
注册 2005-10-12
状态 离线
|
『第 16 楼』:
使用 LLM 解释/回答一下
第一次看到NUL有这种用法
The first time I saw NUL used in this way
|
|
2006-5-11 14:00 |
|
|
chineselgs
高级用户
    论坛灌水专业户
积分 613
发帖 266
注册 2006-4-19 来自 河南省
状态 离线
|
『第 17 楼』:
使用 LLM 解释/回答一下
呵呵看了半天,就是不懂!~~
Hehe, after looking at it for a long time, I just don't understand!~~
|

饮马恒河畔,剑指天山西,碎叶城揽月,库叶岛赏雪,黑海之滨垂钓,贝尔加湖面张弓;中南半岛访古,东京废墟祭祖!
|
|
2006-5-11 16:18 |
|
|
arding
初级用户
 
积分 90
发帖 38
注册 2006-1-6
状态 离线
|
『第 18 楼』:
使用 LLM 解释/回答一下
Originally posted by chenall at 2006-3-26 14:38:
指定了2次句柄3当然无法同时使用了,把第二个改成echo. 1>nul 4>nul看看
确实可以.
恢复分别用echo 2>con 5>con , echo 1>con 6>con,若是只想栮..
我们讨论的对象中都出现了两个 > ,用i,j表示0到9的数字,如果将句柄看作指向设备的指针,则默认时:
句柄 指向
stdin con
stdout con
stderr con
当命令cnd i>nul j>nul 中的第一个>被执行时,系统将的目标暂存于未用的句柄空间,如,已备命令结束时恢复。然而,第二个>使得暂存的内容被修改,于是给后续命令留下了影响。
实际上,cnd i>nul j>nul 又会将的原内容暂存于再一个未用空间内,所以
cnd 2>nul 3>nul 对输出的改变,能够用cnd 2>&3 4>&3恢复回来。
由于暂存位置由系统选择,作为用户无法左右,所以数值不能肯定。
(我的每次试验为了保证句柄空间的确定,都是重新进入cmd.)
Originally posted by chenall at 2006-3-26 14:38:
You can't use handle 3 simultaneously if it's specified twice. Try changing the second one to echo. 1>nul 4>nul and see.
Indeed, it works.
To restore, use echo 2>con 5>con respectively, echo 1>con 6>con. If you only want to...
Among the objects we are discussing, there are two >. Using i and j to represent numbers from 0 to 9, if we regard the handle as a pointer to the device, then by default:
Handle Points to
stdin con
stdout con
stderr con
When the first > in the command cnd i>nul j>nul is executed, the system temporarily stores the target of in an unused handle space, such as , for restoration when the command ends. However, the second > modifies the temporarily stored content, thus leaving an impact on subsequent commands.
In fact, cnd i>nul j>nul will also temporarily store the original content of in another unused space. So
The change in output from cnd 2>nul 3>nul can be restored using cnd 2>&3 4>&3.
Since the temporary storage location is selected by the system and cannot be controlled by the user, the values cannot be determined.
(Each time I test, to ensure the certainty of the handle space, I always re-enter cmd.)
|
|
2006-5-12 13:17 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 19 楼』:
使用 LLM 解释/回答一下
Re arding:
由于暂存位置由系统选择,作为用户无法左右,所以数值不能肯定
我在13楼中猜测,cmd将其修改前的句柄存放在“从未访问过的未定义句柄中(3-9)”。这里再明确一下,其中的“从未访问过”,是指在当前的cmd命令行中用户从未显式指定过,而并非cmd本身未使用过,而“从未访问过”的句柄可能有多个,而cmd会选择第一个。如果你有反面的例证,不妨提出。
Regarding:
Because the temporary location is selected by the system and users cannot control it, so the value cannot be determined
I guessed in floor 13 that cmd stores the handle before modification in "unvisited undefined handles (3-9)". Here, I will clarify again. The "unvisited" here means that the user has never explicitly specified it in the current cmd command line, not that cmd itself has not used it. And there may be multiple "unvisited" handles, and cmd will choose the first one. If you have counterexamples, feel free to put them forward.
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-5-13 18:49 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 20 楼』:
使用 LLM 解释/回答一下
Re arding:
我自己得到了反证,在执行了以下两句后,命令行仍然被屏蔽了。
echo test 3>nul
echo test 1>nul 3>nul
也就是说,我们尽管在第一句中已经访问了句柄3,但仍然可以在第二句中使用3>nul来改变备份的句柄stdout[1]。
因此,cmd的句柄备份策略可能是这样:首先使用未定义句柄3,如果检测到这个句柄处在备份状态时被改动,则换用下一个句柄。
另外还有一些发现:
1、cd 1>nul 2>nul 3>nul 4>nul 可以直接改变stdout和stderr的输出;
2、cd 0<nul 3<nul 或者 cd 0<nul 3>nul 将导致cmd不断回显命令行提示;
3、cd 0<nul 3<file 则直导致 cmd 窗口被关闭;
4、cd 1>nul 3>nul 后,cls 的行为也会失效,因此确证cls也是一种输出行为;
最后,关于句柄的复制,实际上可以理解为句柄的重定向,只是此次重定向的目标不再是设备或者文件,而是另一个句柄。
打个比方说,设备或文件是一个蓄水池,句柄就是其管道,命令则是管道上的水泵或者过滤器,而cmd就是一个自成一体的水循环系统。水池的管道从0-9编号,共有10条,0#管为进水管,1#管为排水管,2#管为故障测试管,3-9#管则是未使用的备用管。而0<实际上是打开进水管的阀门,1>则是打开排水管的阀门,而1>&2则打开将1#管到2#管的连接阀。而>nul的则是用水泵将水扬空。
Re regarding:
I have my own counter-evidence. After executing the following two sentences, the command line is still blocked.
echo test 3>nul
echo test 1>nul 3>nul
That is to say, although we have accessed handle 3 in the first sentence, we can still use 3>nul in the second sentence to change the backup handle stdout.
Therefore, the handle backup strategy of cmd may be like this: first use the undefined handle 3, if it is detected that this handle is in the backup state and is changed, then switch to the next handle.
In addition, there are some other discoveries:
1. cd 1>nul 2>nul 3>nul 4>nul can directly change the output of stdout and stderr;
2. cd 0<nul 3<nul or cd 0<nul 3>nul will cause cmd to continuously echo the command line prompt;
3. cd 0<nul 3<file will directly cause the cmd window to close;
4. After cd 1>nul 3>nul, the behavior of cls will also fail, so it is confirmed that cls is also an output behavior;
Finally, regarding the copying of handles, it can actually be understood as the redirection of handles, but this time the target of redirection is no longer a device or a file, but another handle.
To give an example, the device or file is a reservoir, the handle is its pipe, the command is the water pump or filter on the pipe, and cmd is a self-contained water cycle system. The pipes of the reservoir are numbered from 0-9, there are 10 in total. The 0# pipe is the inlet pipe, the 1# pipe is the drain pipe, the 2# pipe is the fault test pipe, and the 3-9# pipes are unused backup pipes. And 0< is actually opening the valve of the inlet pipe, 1> is opening the valve of the drain pipe, and 1>&2 is opening the connection valve from the 1# pipe to the 2# pipe. And >nul is using a water pump to empty the water.
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-5-14 17:15 |
|
|
arding
初级用户
 
积分 90
发帖 38
注册 2006-1-6
状态 离线
|
『第 21 楼』:
使用 LLM 解释/回答一下
Re Willsort:
通过反复试验,可以猜测系统的句柄使用策略,比如 cnd 2>nul 3>nul 对输出的改变,能够用cnd 2>&3 4>&3恢复回来。 一句中的 4 便是猜测的结果,这也是基于刚刚进入cmd,句柄的使用情况比较清楚地情况下的猜测。
如果在一个批处理中反复使用了句柄重定向,则难以判断其句柄空间的情况,所以我说“系统决定,用户难以左右”。
我同意你的关于“未用句柄”的概念,测试也证实了这个概念。实际上,我感觉到明确的概念至关重要,反之则贻害无穷。就像windows帮助那些似是而非的说明,只会使人更加糊涂。
Re Willsort:
Through trial and error, one can guess the system's handle usage strategy. For example, in the sentence " cnd 2>nul 3>nul changes the output, and it can be restored with cnd 2>&3 4>&3", the number 4 is the result of the guess, which is based on the relatively clear situation of handle usage just when entering cmd.
If handle redirection is repeatedly used in a batch script, it is difficult to judge the situation of the handle space. So I said "the system decides, and users can hardly control".
I agree with your concept of "unused handles", and the test has confirmed this concept. In fact, I feel that clear concepts are crucial; otherwise, it will cause great harm. Just like the ambiguous explanations in Windows help, which will only make people more confused.
|
|
2006-5-15 11:38 |
|
|
weilong888
银牌会员
    
积分 1270
发帖 548
注册 2004-5-31
状态 离线
|
|
2006-10-12 08:00 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 23 楼』:
使用 LLM 解释/回答一下
经典, 又扩展思路了, 句柄重定向!
Classic, and it broadens the thinking! Handle redirection!
|
|
2006-10-12 09:47 |
|
|
soker
初级用户
 
积分 30
发帖 15
注册 2005-8-13
状态 离线
|
『第 24 楼』:
使用 LLM 解释/回答一下
看不懂啊~ 努力ing......
Can't understand~ Working hard...
|
|
2006-10-12 10:15 |
|
|
qq82015930
中级用户
  
积分 235
发帖 109
注册 2006-8-24
状态 离线
|
|
2006-10-12 11:41 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 26 楼』:
使用 LLM 解释/回答一下
两位实在是令人敬佩,但最终给人的感觉,还是没有明确说明句柄重定向的原理,尽管举了几个例子。
The two are really admirable, but in the end, it still gives the feeling that the principle of handle redirection is not clearly explained, although several examples are given.
|
|
2006-10-12 13:34 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 27 楼』:
使用 LLM 解释/回答一下
知道有这回事就行啦。不懂的看Linux Shell入门
Just know that such a thing exists. Those who don't understand can refer to "Introduction to Linux Shell"
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-10-12 21:55 |
|
|
jinnee
新手上路

积分 8
发帖 2
注册 2006-4-24
状态 离线
|
『第 28 楼』:
使用 LLM 解释/回答一下
看了这篇文章大长见识,不过还希能有高手来指点大家,顶一下
After reading this article, I have gained a lot. However, I still hope that experts can come to guide everyone. Give it a thumbs up.
|
|
2006-10-14 03:41 |
|
|
jianyaogao
初级用户
 
积分 49
发帖 22
注册 2005-8-4
状态 离线
|
|
2007-3-17 20:29 |
|
|
axi
中级用户
   脚本爱好者
积分 238
发帖 93
注册 2007-3-11 来自 GZ
状态 离线
|
『第 30 楼』:
使用 LLM 解释/回答一下
哗!这些学识是从哪里学的呢,高深到极!
Wow! Where did you learn these profound knowledge? It's extremely deep!
|
|
2007-3-18 01:43 |
|