1

我需要一个批处理文件“master.bat”,它在执行时会创建一个带有给定文档的新批处理文件“children.bat”:代码是

@echo 关闭

"pre.txt" (for /f "tokens=3,4" %%a in ('net statistics workstation ^| find "since"') do (echo %%a %%b)) 退出

4

2 回答 2

0

要创建包含该代码的新批处理文件:

只需echo将代码发送到您想要的文件中(>

echo @echo off "pre.txt" (for /f "tokens=3,4" %%a in ( 'net statistics workstation ^| find "since"' ) do ( echo %%a %%b )) exit > mybat.bat

要以有效的方式运行该代码:

for /f "tokens=3,4" %%a in ( 'net statistics workstation ^| find "since"' ) do ( echo %%a %%b >> pre.txt )

创建并运行批处理文件

echo @echo off > children.bat
echo for /f "tokens=3,4" %%%%a in ( 'net statistics workstation ^^^| find "since"' ) do ( echo %%%%a %%%%b ^>^> pre.txt ) >> children.bat && children.bat
于 2013-07-26T08:41:55.903 回答
0
@echo off
title Just a sandbox test
color f
:start
cls
set "file=%userprofile%\Desktop\children.bat
(
echo ^@echo off
echo ^"pre.txt^" ^(for /f ^"tokens=3,4^" ^%^%a in ^( ^'net statistics 
workstation ^^^| find echo ^"since^"^' ^) do ^( echo ^%^%a ^%^%b ^)^) exit
) >%file%

::rest of your code goes here I guess
pause

刚刚测试,这将工作。在通常与语法冲突的字符之前添加 ^ 将强制脚本忽略它。:)

附言。抱歉有点晚了lol

于 2017-12-23T11:39:57.227 回答