Visual studio 2012, postbuild event, bat file not creating a new file (not executing)

I have a bat file with code:

echo Hello There > Result.txt @exit 0 

The file is located in a folder named "package", which is located in the root of the project.

I call it with this code in the post-build event:

 call "$(ProjectDir)batch\post.bat" 

I use @exit 0 because otherwise I get error code 1 (which, it seems to me, tells me that the command failed).

When I double click on the bat file or get called from cmd, it creates the file. What do I need to do to make this work.

EDIT: Guys, make sure your file is ASCII encoded. I created mine with VS, which by default sets the encoding to UTF.

+2
visual-studio-2012 batch-file post-build-event
source share
2 answers

Modify the batch file to get the $ (ProjectDir) macro as the first parameter, and then modify the PostBuild event to pass this macro

Post.bat

 echo Hello There > %1%Result.txt @exit 0 

PostBuild Event

 call "$(ProjectDir)batch\post.bat" $(ProjectDir)batch\ 

Your previous command failed because the postbuild event is fired inside the Current Output directory of your executable (usually BIN \ DEBUG or RELEASE). You can easily verify this by adding the dir command with the redirect to result.txt in the above example

+4
source share

Check the project directory for the file, since the batch file is running, but with the current directory $ (ProjectDir), and not in the batch directory.

0
source share

All Articles