在这里,我想知道如何从cmd运行批处理文件(E:\ Programfiles \ bi \ example.bat)

时间:2021-10-17 02:31:50

I tried running it by passing the exact path: E:\Program files\bi\example.bat but it didn't work.

我尝试通过传递确切的路径来运行它:E:\ Program files \ bi \ example.bat但它不起作用。

2 个解决方案

#1


1  

Well it should work if you get the path right.

如果你正确的道路,它应该工作。

"E:\Program files\bi\example.bat"

Program Files has a space in it. That also means it needs to be wrapped in quotes.

Program Files中有一个空格。这也意味着它需要用引号括起来。

Pressing Ctrl + D/Ctrl + F at the command prompt will autofill. This will make sure you have the right path. From Help (cmd /?).

在命令提示符下按Ctrl + D / Ctrl + F将自动填充。这将确保您拥有正确的道路。来自帮助(cmd /?)。

If completion is enabled with the /F:ON switch, the two control characters used are Ctrl-D for directory name completion and Ctrl-F for file name completion. To disable a particular completion character in the registry, use the value for space (0x20) as it is not a valid control character.

如果使用/ F:ON开关启用完成,则使用的两个控制字符是Ctrl-D用于目录名称完成,Ctrl-F用于文件名完成。要禁用注册表中的特定完成字符,请使用空格值(0x20),因为它不是有效的控制字符。

#2


0  

Paths should always be wrapped in double quotes " as each substring after a whitespace is seen as a new command, or switches for a command.

路径应始终用双引号括起来“将空格后的每个子字符串视为新命令,或切换命令。

If you know the Path, simply enter wrapped by "

如果你知道Path,只需输入包裹的“

"E:\Program files\bi\example.bat"

Alternatively, the example.bat might have other switches which calls files in the directory it exists which will then be search for by the path you started cmd.exe from i.e. C:\windows\system32 which will result in a batch file that starts up, but does not work as expected. You can therefore simply cd to the path and run it if successfully changed dir.

或者,example.bat可能有其他开关调用它所在目录中的文件,然后由你从C:\ windows \ system32启动cmd.exe的路径搜索,这将导致启动的批处理文件,但没有按预期工作。因此,如果成功更改了dir,您可以简单地cd到路径并运行它。

cd "E:\Program files\bi" && example.bat

The above can be easier achieve by using your TAB key simply by starting to type the relevant Directory and then TAB which will give you the predictions of directories that exists starting with the given name.

通过使用您的TAB键,只需开始键入相关的目录,然后使用TAB,可以更容易地实现上述目的,这将为您提供以给定名称开头的目录的预测。

If for instance you are not sure where the file is and considering it is the only file by this name, you can simply search for it and execute if found.

例如,如果您不确定该文件的位置,并且认为它是此名称的唯一文件,则只需搜索它并在找到时执行。

for /f "delims=" %a in ('dir /S /B /A-D example.bat') do set "variable=%a" & "%variable%"

The above line will search from the directory you run it from, but search all subfolders and once found, it will execute it. Note, should you want to run the above from a batch file, add another % to the variable %a

上面的行将从您运行它的目录中搜索,但搜索所有子文件夹,一旦找到,它将执行它。注意,如果要从批处理文件运行上述内容,请将另一个%添加到变量%a

for /f "delims=" %%a in ('dir /S /B /A-D example.bat') do set "variable=%%a" & "%variable%"

#1


1  

Well it should work if you get the path right.

如果你正确的道路,它应该工作。

"E:\Program files\bi\example.bat"

Program Files has a space in it. That also means it needs to be wrapped in quotes.

Program Files中有一个空格。这也意味着它需要用引号括起来。

Pressing Ctrl + D/Ctrl + F at the command prompt will autofill. This will make sure you have the right path. From Help (cmd /?).

在命令提示符下按Ctrl + D / Ctrl + F将自动填充。这将确保您拥有正确的道路。来自帮助(cmd /?)。

If completion is enabled with the /F:ON switch, the two control characters used are Ctrl-D for directory name completion and Ctrl-F for file name completion. To disable a particular completion character in the registry, use the value for space (0x20) as it is not a valid control character.

如果使用/ F:ON开关启用完成,则使用的两个控制字符是Ctrl-D用于目录名称完成,Ctrl-F用于文件名完成。要禁用注册表中的特定完成字符,请使用空格值(0x20),因为它不是有效的控制字符。

#2


0  

Paths should always be wrapped in double quotes " as each substring after a whitespace is seen as a new command, or switches for a command.

路径应始终用双引号括起来“将空格后的每个子字符串视为新命令,或切换命令。

If you know the Path, simply enter wrapped by "

如果你知道Path,只需输入包裹的“

"E:\Program files\bi\example.bat"

Alternatively, the example.bat might have other switches which calls files in the directory it exists which will then be search for by the path you started cmd.exe from i.e. C:\windows\system32 which will result in a batch file that starts up, but does not work as expected. You can therefore simply cd to the path and run it if successfully changed dir.

或者,example.bat可能有其他开关调用它所在目录中的文件,然后由你从C:\ windows \ system32启动cmd.exe的路径搜索,这将导致启动的批处理文件,但没有按预期工作。因此,如果成功更改了dir,您可以简单地cd到路径并运行它。

cd "E:\Program files\bi" && example.bat

The above can be easier achieve by using your TAB key simply by starting to type the relevant Directory and then TAB which will give you the predictions of directories that exists starting with the given name.

通过使用您的TAB键,只需开始键入相关的目录,然后使用TAB,可以更容易地实现上述目的,这将为您提供以给定名称开头的目录的预测。

If for instance you are not sure where the file is and considering it is the only file by this name, you can simply search for it and execute if found.

例如,如果您不确定该文件的位置,并且认为它是此名称的唯一文件,则只需搜索它并在找到时执行。

for /f "delims=" %a in ('dir /S /B /A-D example.bat') do set "variable=%a" & "%variable%"

The above line will search from the directory you run it from, but search all subfolders and once found, it will execute it. Note, should you want to run the above from a batch file, add another % to the variable %a

上面的行将从您运行它的目录中搜索,但搜索所有子文件夹,一旦找到,它将执行它。注意,如果要从批处理文件运行上述内容,请将另一个%添加到变量%a

for /f "delims=" %%a in ('dir /S /B /A-D example.bat') do set "variable=%%a" & "%variable%"