China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-12 03:21
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] Simulating command-line handle operations (to help understand handle copying and backup) View 1,033 Replies 5
Original Poster Posted 2009-06-12 11:55 ·  中国 山西 运城 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
s11ss +15 2009-06-13 12:32
Floor 2 Posted 2009-06-13 12:36 ·  中国 北京 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
So how do you tell what a handle points to?
echo 1&handle number to test is con
If con is displayed, then the handle value is con.
Otherwise it is nul or a file.


I didn't understand this part.
Floor 3 Posted 2009-06-13 21:11 ·  中国 山西 运城 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
A typo correction:
echo 1&handle number to test is con
should be
echo 1<&handle number to test is con

It is equivalent to
echo is con 1<&handle number

Example analysis:
1<&7

means copying what handle 7 points to into handle 1.
And the output of echo is sent through handle 1 by default.
So if handle 7 points to con,
after copying it to 1, then 1 also points to con.
Then the output of echo will appear on the screen.
Otherwise it will not appear on the screen.

Of course, this is only a simple way to tell con from non-con.
For more specific methods, you'll still need to do more testing yourself.

[ Last edited by qzwqzw on 2009-6-13 at 21:14 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
s11ss +3 2009-06-14 04:30
Floor 4 Posted 2009-06-14 04:32 ·  中国 北京 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Originally posted by qzwqzw at 2009-6-13 09:11 PM:
A typo correction:
echo 1&handle number to test is con
should be
echo 1<&handle number to test is con

It is equivalent to
echo is con 1<&handle number

Example analysis:
1<&7

means ...


<& seems to be the same as >&, both copy the latter handle to the former handle.
Floor 5 Posted 2009-06-14 21:18 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Now I found that the only difference between >& and <&
is the default value on the left side.
The default left value of >& is 1.
The default left value of <& is 0.
The resulting effect is that after
echo. >nul 3>nul makes handle 1 become nul,
echo Hello Handle <&2 has no output
echo Hello Handle >&2 has output
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
s11ss +3 2009-06-14 23:19
Floor 6 Posted 2009-06-14 23:11 ·  中国 北京 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Originally posted by qzwqzw at 2009-6-14 09:18 PM:
Now I found that the only difference between >& and <&
is the default value on the left side.
The default left value of >& is 1.
The default left value of <& is 0.
The resulting effect is that after
echo. >nul 3>nul ...

hh ntcmds.chm::/redirection.htm

If no handle is defined, the default handle for the < redirection input operator is 0, and the default handle for the > redirection output operator is 1.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
uiopuiop +1 2009-06-15 10:00
Forum Jump: