运行一个输入参数作为DOS批处理脚本命令? [英] run a input parameter as command in dos batch script?
问题描述
如何我在DOS脚本输入参数运行命令?
How can I run a command in my dos script from an input argument ?
简体脚本bla.bat:结果
  CALL%1
Simplified script bla.bat:
CALL %1
调用它:结果
bla.bat回声'你好'(或bla.bat混帐地位)
Call it:
bla.bat "echo 'hello'" (or bla.bat "git status")
错误:结果
混帐地位'无法识别为一个内部或外部命令,
可运行的程序或批处理文件。
Error:
'"git status"' is not recognized as an internal or external command,
operable program or batch file.
它的工作原理,如果我做CALL git的状态。
It works if I do "CALL git status".
推荐答案
看起来问题可能是你已经围绕在你输入引号,你需要阻止它被分成不同的%N参数,但尝试:
It looks like the problem may be that you have surrounding quotes in your input, which you'll need to stop it being broken into the different %n arguments, but try:
%〜1
将从输入剥离任何引号。
%~1
Which will strip any surrounding quotes from the input.
%〜$ PATH:1
这将剥夺然后任何引号的$ PATH环境-VAR的第一场比赛中进行搜索,然后展开字符串包含完整的路径命令,GIT中使用Windows的发行版,因为Git是一个批处理文件,将不工作,CMD会寻找混帐status.bat
%~$PATH:1
which will strip any surrounding quotes then search within the $PATH env-var for the first match, then expand the string to include the full path to the command, which won't work for git using the windows distro because git is a batch file, and cmd would look for git status.bat
如果其与git的使用,你不妨使用%〜1%和2〜叫混帐然后提供的参数,git的批处理文件,或通过修改$ PATH git.exe直接调用。但请记住,git.bat做一些自己的环境设置调用的git本身之前。
If its to be used with git, you may as well use %~1 and %~2 to call git then provide the argument to the git batch file, or call git.exe directly by modifying your $PATH. But remember that git.bat does some enviroment setup of its own before calling git itself.
这篇关于运行一个输入参数作为DOS批处理脚本命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!