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-10 00:55
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Closed] How to directly execute batch commands in a text file in the CMD window View 1,516 Replies 11
Original Poster Posted 2008-02-15 18:07 ·  中国 浙江 嘉兴 海宁市 电信
中级用户
★★
Credits 360
Posts 216
Joined 2007-05-29 17:41
19-year member
UID 89677
Gender Male
Status Offline
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 ]
Floor 2 Posted 2008-02-15 18:16 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
type 10.txt|cmd /k

Note: Lines with commands in the 10.txt file must be entered with a carriage return.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
bd123456789 +1 2008-02-16 11:33
Floor 3 Posted 2008-02-15 18:32 ·  中国 浙江 嘉兴 海宁市 电信
中级用户
★★
Credits 360
Posts 216
Joined 2007-05-29 17:41
19-year member
UID 89677
Gender Male
Status Offline
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 ]
Floor 4 Posted 2008-02-15 19:59 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Probably because of the previous "cmd /k", I don't know the specific reason.
Floor 5 Posted 2008-02-15 22:46 ·  中国 河北 保定 移动
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
for /f "tokens=*" %i in (10.txt) do %i
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 6 Posted 2008-02-16 11:31 ·  中国 浙江 嘉兴 海宁市 电信
中级用户
★★
Credits 360
Posts 216
Joined 2007-05-29 17:41
19-year member
UID 89677
Gender Male
Status Offline
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!
Floor 7 Posted 2008-02-16 12:48 ·  中国 广东 揭阳 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
Floor 8 Posted 2008-02-16 12:49 ·  中国 广东 揭阳 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
bd123456789 +1 2008-02-16 13:13
wishpopo +1 2008-11-03 22:18
Floor 9 Posted 2008-02-17 11:27 ·  中国 浙江 嘉兴 海宁市 电信
中级用户
★★
Credits 360
Posts 216
Joined 2007-05-29 17:41
19-year member
UID 89677
Gender Male
Status Offline
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 ]
Floor 10 Posted 2008-02-17 12:14 ·  中国 山东 青岛 阿里云
版主
★★★
操作系统爱好者
Credits 1,113
Posts 392
Joined 2002-11-11 00:00
23-year member
UID 228
Gender Male
Status Offline
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
DOS之家 http://doshome.com 站长 葛明阳
Floor 11 Posted 2008-11-03 22:21 ·  中国 河南 郑州 联通
新手上路
Credits 18
Posts 20
Joined 2008-10-28 22:45
17-year member
UID 129408
Gender Male
Status Offline
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.
Floor 12 Posted 2008-11-04 10:56 ·  中国 北京 中移铁通
初级用户
Credits 22
Posts 17
Joined 2007-12-11 09:35
18-year member
UID 105288
Gender Male
Status Offline
Got it!
I always directly edit the txt into bat
Forum Jump: