Include batch file in batch file

I had a problem calling a batch file from another batch file while trying to run everything using Process.Start. I basically call the execution of a batch file from my C # program, which looks like this:


call include.bat  

//execute the rest of the batch file here  

The include.bat file sets the paths and can be used by a number of other batch files. When I start Process.Start, sometimes it works, and sometimes I get ERROR: cannot find include.bat. First of all, any idea why this is happening? And ideas on how to fix this from a batch file?

+5
source share
5 answers

To switch to the directory where the batch file is located, use this:

cd %~dp0

. , .

+7

script CD /D %~dp0

+2

, , , , , (.. ), .

- :

call "%~dp0include.bat"

( % ~ dp0 , .)

:

  • .
  • "SETLOCAL".
  • UNC- (,\\server\share\file.bat), , ( "cd/d" ) . ( pushd/popd , .)

, , .

+2

include.bat. , , , . , # " ", , .

+1
source

Are you setting ProcessStartInfo.WorkingDirectory ( http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.workingdirectory.aspx ) to the ProcessStartInfo that you pass to Process.Start?

Since include.bat sometimes cannot be found, the working directory may be incorrect (not the folder where include.bat is located).

+1
source

All Articles