中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-08 23:19
47,811 topics / 349,895 posts / today 0 new / 48,253 members
DOS批处理 & 脚本技术(批处理室) » How to read the first letter of each line and execute this command.
Printable Version  5,482 / 17
Floor1 online365 Posted 2006-11-06 17:54
初级用户 Posts 75 Credits 182
The content of 1.txt is as follows: (one letter per line)

c
h
k
d
s
k

I want to combine them to execute the chkdsk command~~ I don't know how to write it.

[ Last edited by namejm on 2006-11-6 at 09:08 PM ]
Floor2 redtek Posted 2006-11-06 22:07
金牌会员 Posts 1,147 Credits 2,902
Originally, I wanted to communicate with the LZ about the questions raised above (very interesting), but after thinking for a long time, I didn't know how to answer : )
Now I don't even know whether to consider it as purely DOS discussion or the CMD Shell of the XP system that everyone uses...

After I searched most of the LZ's posts in the forum search, I determined that this question is about non-pure DOS issues, haha...



Seeing that there are problems about <> and for /f reading files and other problems mentioned by the LZ,
Then are these interesting problems supposed to be interesting solutions?

The interesting solution is as follows, it is the way of "writing" itself to read chkdsk and then directly run automatically.
For fun, so it can only run correctly once, haha...
But the LZ's wanted those problem characteristics and redirection and reading files are all used up : )
Also, the LZ may be interested in how not to write redundant carriage return characters at the end... is also used up : )

The following example is only for fun, not practical : )


The @, in the last line has a reason, it is to prevent you from directly saving the first line and not giving a line feed,
So, @, is that when encountering the following DOS command can also execute normally,
But this interesting method can only execute normally once~ : D



The "%~f0" used above is the full name of the batch processing's own drive letter path filename, this information can find more messages in the help information of for /? : )
Using Del "%~f0" can also let the batch processing "commit suicide", that is, delete itself~

Self (batch processing itself) writing new information to itself can also be used for special applications such as simple running times or running logs...

The >>"%~f0" used in the above batch processing is appending the output information to cover the target file content's situation to append to the target file content's behind.
And why does "%~f0" want to add %~f0 (that is, batch processing oneself's entire path and other information) with double quotes? It is because if you run where there are spaces (such as desktop),
Then in order to cause the system wrong judgment middle spaces...
For example: CD ABC 123 is not getting into "ABC 123" this directory, to add double quotes the system just knows this is integral,
So the above batch processing oneself information's expression要用 double quotes enclose : )


set /p=%%.<nul is to remove that your 1.txt all took carriage return line feed characters of "c h k d s k",
As for why it can "remove" carriage return and line feed symbols, there is a allusion inside, hee hee...

Need to appreciate the following wonderful article like reading a story:
----------------------------------------------------------------------------------------------------
Brief Analysis of Helpless Signature Code
http://www.cn-dos.net/forum/viewthread.php?tid=18838&fpage=1&highlight=%E7%AD%BE%E5%90%8D
----------------------------------------------------------------------------------------------------
After reading the above article, the LZ can make more interesting things~ : )
(If the friend who hasn't read this article, please put down any thing in hand, go to see "Brief Analysis of Helpless Signature Code" now)
(The most useless is collection, the most useful is to use go to see go to study go to do once to replace the action of collecting uselessly)

[ Last edited by redtek on 2006-11-6 at 10:38 PM ]
Floor3 NaturalJ0 Posted 2006-11-06 22:19
银牌会员 Posts 533 Credits 1,181
Floor4 ccwan Posted 2006-11-06 23:22
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Amazing! Interesting!
Floor5 namejm Posted 2006-11-07 01:38
荣誉版主 Posts 1,737 Credits 5,226 From 成都
The principle has been posted by redtek, so I won't say more. Here's a piece of code that can get the correct result when executed multiple times:
Floor6 lxmxn Posted 2006-11-07 01:45
版主 Posts 4,938 Credits 11,386

  Great~~ quite interesting~~
Floor7 online365 Posted 2006-11-07 08:11
初级用户 Posts 75 Credits 182
Thanks a lot to the two great experts redtek and namejm. The problem has been successfully solved, but I don't understand the code very much. I'm continuing to study...
Floor8 zerostudy Posted 2006-11-07 08:56
中级用户 Posts 98 Credits 266
set var=!var!%%i
Set a variable var, and its value is!var!(which is itself.) %%i is read from the text.
!var! is empty at the beginning. So in the first time of the for loop, it is var=c. Then it loops again.. At this time, var=C plus h, which is var=ch..
In the end, it becomes chkdsk...
Floor9 vkill Posted 2006-11-07 08:58
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
I don't know if the first letter has any special characters
Floor10 online365 Posted 2006-11-08 09:49
初级用户 Posts 75 Credits 182
Thanks to the explanation from user 8...

Little brother has another question...
If the content in the text is not as simple as the above, but I want to specify and extract the content inside to display, still like the above example to extract chkdsk to one line (the first two lines and the last line are deliberately written more)

yyyyy
bbbb
abca
ghdk
jkl
cde
sss
kkmm
hhhhyy

I wonder if there is a way?
Floor11 namejm Posted 2006-11-08 11:28
荣誉版主 Posts 1,737 Credits 5,226 From 成都
May I ask, what is the regularity of your text content? And what is the regularity of the content to be extracted? Your example in 10F is completely confusing.
Floor12 lxmxn Posted 2006-11-08 12:42
版主 Posts 4,938 Credits 11,386

Re namejm:
Actually, he still wants to extract chkdsk, but the first two lines and the last line are deliberately confusing you, heh heh``
Floor13 online365 Posted 2006-11-08 13:26
初级用户 Posts 75 Credits 182
lxmxn is right, just want to extract chkdsk from the example of 10F.. (The first two lines and the last line are written intentionally more)
Floor14 lxmxn Posted 2006-11-08 13:51
版主 Posts 4,938 Credits 11,386

  But let me tell you, this is completely meaningless. Because the letters in the line where the letters to be extracted are located have no pattern at all. If you want to test the "encryption" effect, you can place each character in a command at the same position in each line. For example, the following lines can be used as the text to extract the "ping" command.

-----------------------------------
abcpdafd
wdeiaedlafjklsjfeil
efanfeildjf
sajglielajgfia
-----------------------------------
  Extract the fourth character of each line.
Floor15 zh159 Posted 2006-11-08 13:52
金牌会员 Posts 1,467 Credits 3,687
It's better to just chkdsk.

Or just one line: abcdefghijklmnopqrstuvwxyz
Then extract with %N:~n,1%
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023