2

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.

Ivan Davidov
  • 823
  • 1
  • 9
  • 24

2 Answers2

4

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

Steve
  • 213,761
  • 22
  • 232
  • 286
  • This was it, when I finally got it working... The problem was that I created bat file with visual studio dialog and got some utf chars messing up my script. Found out that while testing script in cmdline - saw some strange characters appearing and text not echoed into new file. Solved by creating new file in native notepad - ascii. You were right, file was initially created in bin folder. Thanks for your help. – Ivan Davidov May 29 '13 at 21:04
0

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.

Photon
  • 3,182
  • 1
  • 15
  • 16