如何在同一行上创建两个 cmd 命令

如何在同一行上创建两个 cmd 命令

我浏览了很多这样的帖子,但没有找到任何具体的有帮助的内容,所以这是我的问题:

echo START %USERNAME% > exec3.txt & dir c: /B /S | find ".exe" >> exec3.txt & echo STOP %username% >> exec3.txt

并且我需要在此exec.txt文件中输出用户名和.exe 路径在同一行,而不是上下。

我在这方面还是新手,所以如果你能帮助我,谢谢。

编辑:好的,所以我目前从这段代码中得到的是:

START remak  
C:\05b7ba810261bb83a30acb4b8289\Setup.exe
C:\05b7ba810261bb83a30acb4b8289\SetupUtility.exe
C:\0f669298b95e17eb4420fab939d6058e\Setup.exe
C:\0f669298b95e17eb4420fab939d6058e\SetupUtility.exe
C:\5179a24a27196222747e\Setup.exe
C:\5179a24a27196222747e\SetupUtility.exe
C:\611f293b57db179b197d\Setup.exe
C:\611f293b57db179b197d\SetupUtility.exe
C:\doublecmd\doublecmd.exe

STOP REMAK

Remak 是用户名,我需要 REMAK 与路径位于同一行,如下所示:

REMAK C:\05b7ba810261bb83a30acb4b8289\Setup.exe

答案1

::This is a comment

::Stops the console window from being spammed (and therefore speeds things up a bit)
@echo off

::Create a new file (WARNING: THIS OVERWRITES EXISTING FILES)
type NUL > exec.txt

::Loop through each line outputted by the command 'dir /b /s C:\*.exe'
::The echo command is executed once for each loop iteration
::This can take a very long time, depending on how big your C: partition is
for /f "tokens=*" %%a in ('dir /b /s C:\*.exe') do (
    echo START %USERNAME% %%a STOP %USERNAME%>>exec.txt
)

相关内容