![]() |
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-10 01:39 |
47,811 topics / 349,897 posts / today 2 new / 48,255 members |
| DOS批处理 & 脚本技术(批处理室) » [Closed] How to directly execute batch commands in a text file in the CMD window |
| Printable Version 1,518 / 11 |
| Floor1 bd123456789 | Posted 2008-02-15 18:07 |
| 中级用户 Posts 216 Credits 360 | |
|
10.txt Content is as follows:
at 17:00 shutdown -s How to directly execute the batch code in the text in the CMD window and not rename it to 10.bat, is there any method? In addition, do not use indirect methods such as FOR to read the text! Why doesn't cmd.exe /c 10.txt Or cmd.exe /k 10.txt execute the commands in 10.TXT?? [ Last edited by HAT on 2008-11-4 at 00:46 ] |
|
| Floor2 lxmxn | Posted 2008-02-15 18:16 |
| 版主 Posts 4,938 Credits 11,386 | |
|
Note: Lines with commands in the 10.txt file must be entered with a carriage return. |
|
| Floor3 bd123456789 | Posted 2008-02-15 18:32 |
| 中级用户 Posts 216 Credits 360 | |
|
Thanks
The command "cmd /k type 10.txt | cmd /k" can solve the problem of no line breaks in 10.txt. However, when I enter "at" in the window again to view the plan, some unnecessary things or errors appear. I don't know the reason? [ Last edited by bd123456789 on 2008-2-15 at 06:44 PM ] |
|
| Floor4 lxmxn | Posted 2008-02-15 19:59 |
| 版主 Posts 4,938 Credits 11,386 | |
|
Probably because of the previous "cmd /k", I don't know the specific reason.
|
|
| Floor5 Climbing | Posted 2008-02-15 22:46 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
for /f "tokens=*" %i in (10.txt) do %i
|
|
| Floor6 bd123456789 | Posted 2008-02-16 11:31 |
| 中级用户 Posts 216 Credits 360 | |
|
Such as 10.txt, according to the previous floor to use FOR operation
Setlocal enabledelayedexpansion at 17:35 shutdown -s echo %time% echo !time! at 17:00 start d:\1.txt endlocal Or not enable environment variable delay Or directly enable environment variable delay in the CMD window, both cannot display the time normally And use cmd /k type 10.txt|cmd /k Only need in the text at 17:35 shutdown -s echo %time% at 17:00 start d:\1.txt Is the above statement correct, please everyone test! |
|
| Floor7 523066680 | Posted 2008-02-16 12:48 |
| 银牌会员 Posts 1,133 Credits 2,362 | |
| Floor8 523066680 | Posted 2008-02-16 12:49 |
| 银牌会员 Posts 1,133 Credits 2,362 | |
| Floor9 bd123456789 | Posted 2008-02-17 11:27 |
| 中级用户 Posts 216 Credits 360 | |
|
However,
The shortcomings of the above are also there, that is, an error will occur when there is no carriage return at the last line of the text? But the advantage is that it can automatically exit the CMD program, that is, command <10.txt & exit. And CMD /K TYPE 10.TXT | CMD /K then has no way to automatically exit the program . In addition, I found that using cmd < 10.txt can also execute normally (the disadvantage is that there is a carriage return at the last line). If there is no carriage return, →More? will appear . [ Last edited by bd123456789 on 2008-2-17 at 11:43 AM ] |
|
| Floor10 gmy | Posted 2008-02-17 12:14 |
| 版主 Posts 392 Credits 1,113 | |
|
Copy and Rename Method:
@echo off REM Copy 10.txt to the temporary folder and rename it to 10.bat copy /y 10.txt %temp%\10.bat >nul REM Call the batch file 10.bat in the temporary folder call %temp%\10.bat >nul REM Delete the batch file 10.bat in the temporary folder del %temp%\10.bat >nul REM Exit exit |
|
| Floor11 wishpopo | Posted 2008-11-03 22:21 |
| 新手上路 Posts 20 Credits 18 | |
|
I found that using comand<10.txt is like running with bat, while using CMD /K TYPE 10.TXT|CMD /K is like inputting in DOS. I don't know if it's right. Let everyone say.
|
|
| Floor12 renol | Posted 2008-11-04 10:56 |
| 初级用户 Posts 17 Credits 22 | |
|
Got it!
I always directly edit the txt into bat |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |