开发者

Using Command Prompt To Call a Batch File in a Sub-Directory

I'd like to use a batch file to call a different batch file that is in a sub directory. For instance, if my file system look as follows:

MainFolder

    main.bat

    FirstDirectory

    SecondDirectory

        foo.bat

Then main.bat might look something like this:

开发者_如何学Go
echo on
REM This lines tells the user what this bat file is doing
call ant
call \SecondDirectory\foo.bat

I'm looking for a one line solution which I think does not exist. Unfortunately I don't always want to do this with a batch file and want to do it directly from the command line.


You can indeed call a batch file from another batch file using the call command. As @Blorgbeard states, the issues is the leading backslash \. Removing it indicates SecondDirectory is relative to the current working directory.

call SecondDirectory\foo.bat

A word of caution: the call command essentially inserts called code in at run time. Be careful to avoid variable name collisions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜