gpt4 book ai didi

Windows 批处理 : combining start and FOR/f "tokens=1" with | escape coded symbols

转载 作者:可可西里 更新时间:2023-11-01 11:23:29 25 4
gpt4 key购买 nike

我正在尝试从标准 Windows 批处理文件中执行此命令。

start /B for /f "tokens=1" %%a in ('Query SESSION ^| find /i "rdp"') do (echo yes |reset session %%a)

它抛出一个错误:

"| was unexpected at this time."

我刚刚发现它失败了,因为 start 在开头。有什么问题吗?

最佳答案

从批处理文件中尝试使用 start 构建有效的单行解决方案是个坏主意,转义/引用复杂表达式非常棘手。

但是在同一个批处理文件中使用 start 和跳转到标签非常简单。

@echo off
REM *** Thread redirector
for /F "tokens=3 delims=:" %%F in ("%~0") do goto %%F

REM *** Start a new thread in this batch file at the label :myThread
start "" /b cmd /c "%~d0\:myThread:\..\%~pnx0"

echo Main
for /L %%n in (1 1 10) DO (
echo MainThread doing some stuff %%n
ping localhost -n 2 > nul
)
exit /b

:myThread
for /f "tokens=1" %%a in ('Query SESSION ^| find /i "rdp"') do (
echo myThread: Resetting session %%a
echo yes | reset session %%a
)
exit /b

关于Windows 批处理 : combining start and FOR/f "tokens=1" with | escape coded symbols,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53642279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com