To PLATCH:
运行中接受字符串变量是bat的一大弱点,若是没有其他增强命令的帮忙,单纯依靠DOS 自带的内外部命令来实现这一特征,代码量将是惊人的(我自己曾经试过),而且价值也不是很大。
我遇到此类问题,一般将它转化为从命令行接受字符串参数,然后转移到相应的子程序位点,这实现起来到不太难:
:start
find ":%1" > nul
if errorlevel 0 goto error
goto %1
:proc1
......
:proc2
......
:error
echo Invalid argument!
:end
如果你必须要实现此功能,可以给你一个建议,从主程序中用 %comspec% 抛出一个DOS的子SHELL,用命令行伪装的字符串传入程序,然而将子程序实现为独立的bat程序,直接调用运行。也许我说的不太清楚,如果你想探讨此一问题,再联系!
To PLATCH:
Running and accepting string variables is a major weakness of bat. If there are no other enhanced commands to help, simply relying on the internal and external commands that come with DOS to achieve this feature, the amount of code will be astonishing (I have tried it myself), and the value is not very great.
When I encounter such problems, I generally convert it into accepting string parameters from the command line, and then transfer to the corresponding subroutine site. This is not too difficult to implement:
:start
find ":%1" > nul
if errorlevel 0 goto error
goto %1
:proc1
......
:proc2
......
:error
echo Invalid argument!
:end
If you must implement this function, I can give you a suggestion. Throw out a DOS sub-SHELL from the main program with %comspec%, pass in the string disguised as the command line to the program, and then implement the subroutine as an independent bat program and call it directly. Maybe I didn't make it very clear. If you want to discuss this problem, contact me again!