|
bd123456789
中级用户
  
积分 360
发帖 216
注册 2007-5-29
状态 离线
|
『楼 主』:
[已结]如何在CMD窗口中直接执行文本文件内的批处理命令
使用 LLM 解释/回答一下
文本:10.txt 内容如下:
at 17:00 shutdown -s
如何在CMD窗口中 直接执行文本里面的批处理代码 并且 不改名为10.bat,有啥方法
另外,不使用FOR等间接读取文本的办法!
为什么 cmd.exe /c 10.txt
或者 cmd.exe /k 10.txt 都没执行10.TXT内的命令??
Last edited by HAT on 2008-11-4 at 00:46 ]
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 ]
|
|
2008-2-15 18:07 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
type 10.txt|cmd /k
需要注意:10.txt文件中有命令的行必须回车。
type 10.txt|cmd /k
Note: Lines with commands in the 10.txt file must be entered with a carriage return.
|
|
2008-2-15 18:16 |
|
|
bd123456789
中级用户
  
积分 360
发帖 216
注册 2007-5-29
状态 离线
|
『第 3 楼』:
能解决10.txt不换行的问题
使用 LLM 解释/回答一下
多谢
cmd /k type 10.txt | cmd /k
能解决10.txt不换行的问题
,可是我再在窗口中输入at,以查看计划
,会出现一些不必要的东西或者说错误,不知道是什么原因?
Last edited by bd123456789 on 2008-2-15 at 06:44 PM ]
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 ]
|
|
2008-2-15 18:32 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
大概是因为前面的那个“cmd /k ”,具体原因我不太清楚。
Probably because of the previous "cmd /k", I don't know the specific reason.
|
|
2008-2-15 19:59 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
for /f "tokens=*" %i in (10.txt) do %i
for /f "tokens=*" %i in (10.txt) do %i
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2008-2-15 22:46 |
|
|
bd123456789
中级用户
  
积分 360
发帖 216
注册 2007-5-29
状态 离线
|
『第 6 楼』:
for 因环境变量问题导致执行文本有些不必要的麻烦
使用 LLM 解释/回答一下
如10.txt,据上楼使用FOR操作
Setlocal enabledelayedexpansion
at 17:35 shutdown -s
echo %time%
echo !time!
at 17:00 start d:\1.txt
endlocal
或者不启用环境变量延迟
再或者直接在CMD窗口先启用环境变量延迟,都不能正常显示时间
而使用
cmd /k type 10.txt|cmd /k
文本中只需
at 17:35 shutdown -s
echo %time%
at 17:00 start d:\1.txt
上面的讲法是否正确,请大家测试!
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!
|
|
2008-2-16 11:31 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
|
2008-2-16 12:48 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
|
2008-2-16 12:49 |
|
|
bd123456789
中级用户
  
积分 360
发帖 216
注册 2007-5-29
状态 离线
|
『第 9 楼』:
楼上的,学习了
使用 LLM 解释/回答一下
不过
楼上的缺点也是有的
就是当文本最后一行没有回车时会出错?
但好处是能够自动退出CMD程序
即command<10.txt&exit
而CMD /K TYPE 10.TXT|CMD /K 则没有办法自动退出程序
另外,我发现,使用 cmd < 10.txt 也能正常执行(缺点是最后一行有回车)
没有回车的话,会出现→More?
Last edited by bd123456789 on 2008-2-17 at 11:43 AM ]
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 ]
|
|
2008-2-17 11:27 |
|
|
gmy
版主
        操作系统爱好者
积分 1113
发帖 392
注册 2002-11-11
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
复制改名法:
@echo off
REM 复制10.txt到临时文件夹且更名为10.bat
copy /y 10.txt %temp%\10.bat >nul
REM 调用临时文件夹的批处理10.bat
call %temp%\10.bat >nul
REM 删除临时文件夹的批处理10.bat
del %temp%\10.bat >nul
REM 退出
exit
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 站长 葛明阳 |
|
2008-2-17 12:14 |
|
|
wishpopo
新手上路

积分 18
发帖 20
注册 2008-10-28
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
我发现用comand<10.txt 是像bat运行一样
而 用CMD /K TYPE 10.TXT|CMD /K则像在DOS内输入一样
不知道对对 各位说一下。
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.
|
|
2008-11-3 22:21 |
|
|
renol
初级用户
 
积分 22
发帖 17
注册 2007-12-11
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
学习了!!!!
我每次都是直接编辑txt为bat
Got it!
I always directly edit the txt into bat
|
|
2008-11-4 10:56 |
|