标题: [文本处理] [已解决]语句怎么写入bat [打印本页]
作者: dyhq2021 时间: 2022-1-19 09:14 标题: [已解决]语句怎么写入bat
本帖最后由 dyhq2021 于 2022-1-19 15:14 编辑
- @echo off
- >"%temp%\DateCalculate.vbs" echo dt=date()
- >>"%temp%\DateCalculate.vbs" echo s=right(year(dt),4) ^& "-" ^& right("0" ^& month(dt),2) ^& "-" ^& right("0" ^& day(dt),2)
- >>"%temp%\DateCalculate.vbs" echo wscript.echo s
- for /f %%a in ('cscript /nologo "%temp%\DateCalculate.vbs"') do (
- set Today=%%a
- )
- echo %Today%
- pause
- exit
复制代码
问一下,以上语句怎么写入1.bat
第一句。
echo >"%temp%\DateCalculate.vbs" echo dt=date() >d:\1\gsh.bat
echo dt=date() >"%temp%\DateCalculate.vbs">d:\1\gsh.bat
都不对
作者: Batcher 时间: 2022-1-19 11:48
回复 1# dyhq2021
参考:批处理动态生成脚本或文件
https://mp.weixin.qq.com/s/McvY4CiR-SYGaCha7lmjIw- @echo off
- for /f "delims=:" %%i in ('findstr /n "^:DynamicScript$" "%~f0"') do (
- more +%%i "%~f0" > "1.bat"
- )
- goto :eof
-
- :DynamicScript
- @echo off
- >"%temp%\DateCalculate.vbs" echo dt=date()
- >>"%temp%\DateCalculate.vbs" echo s=right(year(dt),4) ^& "-" ^& right("0" ^& month(dt),2) ^& "-" ^& right("0" ^& day(dt),2)
- >>"%temp%\DateCalculate.vbs" echo wscript.echo s
- for /f %%a in ('cscript /nologo "%temp%\DateCalculate.vbs"') do (
- set Today=%%a
- )
- echo %Today%
- pause
复制代码
作者: dyhq2021 时间: 2022-1-19 13:21
16 行后面 还有代码。不要写入,如何跳出?
作者: Batcher 时间: 2022-1-19 13:22
回复 3# dyhq2021
需要执行的代码放到第4行下面
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |