问题
I have a bat file with code:
echo Hello There > Result.txt
@exit 0
File is located in folder named "batch" which is located in the project root.
I am calling it with this code in post-build event:
call "$(ProjectDir)batch\post.bat"
I am using @exit 0 because otherwise I get error code 1 (which I guess tells me that command didn't succeed).
When I double click on bat file or invoke it from cmd it creates a file. What do I need to do in order to make this work
EDIT: Guys, make sure your file is in ASCII encoding. I've created mine with VS which sets encoding to UTF by default.
回答1:
Change you batch file to receive as first parameter the $(ProjectDir) macro and then change 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 fails because the postbuild event is executed inside the Current Output directory of your executable (usually BIN\DEBUG or RELEASE). You could easily check this adding a dir command with a redirection to the result.txt in the above example
回答2:
Check the project directory for the file, since the batch file is being run, but with a current directory of $(ProjectDir) and not in the batch directory.
来源:https://stackoverflow.com/questions/16823058/visual-studio-2012-postbuild-event-bat-file-not-creating-new-file-not-executi