Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 如何从.bat in循环运行*.exe/key_Windows_Batch File - Fatal编程技术网

Windows 如何从.bat in循环运行*.exe/key

Windows 如何从.bat in循环运行*.exe/key,windows,batch-file,Windows,Batch File,我有目录结构: DIR |-UNINSTALL.BAT |-component_name |-source |-setup.exe |-uninst.bat |-another_component_name |-source |-setup.exe |-uninst.bat |-yet_another_component_name |-source |-setup.exe |-uninst.bat 等等 在像“component_name”这样的每个目录中,

我有目录结构:

DIR
|-UNINSTALL.BAT
|-component_name
  |-source
  |-setup.exe
  |-uninst.bat
|-another_component_name
  |-source
  |-setup.exe
  |-uninst.bat
|-yet_another_component_name
  |-source
  |-setup.exe
  |-uninst.bat
等等

在像“component_name”这样的每个目录中,我都有
setup.exe
文件,该文件将当前组件安装到Delphi中的调色板组件中。
uninst.bat
仅包含以下字符串:

“setup.exe”/uninstall

因此,我需要在
DIR
中编写
UNINSTALL\u ALL.bat
,以便在所有组件目录中运行uninst.bat


提前谢谢。

这在批处理文件中有点像akward。尽管您可能可以使用
foreach
语句来实现这一点。不过,我建议您看看Powershell,它肯定会让您能够简单地执行此操作,如果您需要,还可以执行更多操作。

您可以使用以下命令行执行此操作:

 for /f %%a in ('dir /b /s uninst.bat') do call %%a
请注意,批处理文件需要“%”。如果要在命令行上测试此项,请仅使用一个“%”,如果要使用“for”构造,请使用“%”。大概是这样的:

for %%i in (component_name another_component_name yet_another_component_name) do %%i\uninst.bat
如果在批处理文件中放入“for”循环,则需要双转义(%)。如果您只是在命令提示符下键入,请仅使用1%

此外,如果目录名遵循某种约定,则可以使用通配符来匹配它们。打开命令提示符并运行“for/?”以查看它可以执行的所有操作…我相信有一个a/d选项可以与目录匹配。这看起来像:

for /D %%d in (component_*) do %%d\uninst.bat
(显然,调整通配符以匹配组件目录。)

这应该可以:

FOR /F %%a IN ('dir /b /s uninst.bat') DO START /B %%a
如果希望他们彼此等待,请使用以下命令:

FOR /F %%a IN ('dir /b /s uninst.bat') DO START /B /WAIT %%a

按照您描述问题的方式,您只有一级子目录,并且始终从根目录调用同一批。因此:

卸载_all.cmd

@echo off
for /F "delims=" %%d in ('dir /b /ad') do cd "%%d"& start /b /w ..\uninstall.bat& cd ..

应该做到这一点。

Powershell的一个潜在问题是,它可能没有安装在大多数机箱上,而您始终可以运行批处理文件。OTOH,批处理文件在尝试做复杂的事情时糟糕透顶,所以尽管这件事情可以不太麻烦地完成,但我可以很容易地想象到遇到一种情况,你希望自己使用的是真正的语言。真的。但powershell是作为windows 7、windows 2008 server的一部分提供的,可通过windows update为大多数其他版本的windows提供,并受Microsoft产品支持支持的支持。因此,在受控发布环境中应该可以安装。我认为安装它的好处大于障碍。这是行不通的。一个.bat运行另一个.bat,它运行带有密钥的.exe文件。。。也许根本就不会这样?那应该行。您在控制台上看到了什么类型的错误?你测试过你的uninst.bat单机版吗?