本文介绍了的Visual Studio 2012,postbuild事件,bat文件没有创建新文件(不执行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有code BAT文件:

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.

我在生成后事件这code调用它:

I am calling it with this code in post-build event:

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

我使用@exit 0,否则我得到的错误code 1(我的猜测告诉我,命令没有成功)。

I am using @exit 0 because otherwise I get error code 1 (which I guess tells me that command didn't succeed).

当我上双bat文件点击或CMD它创建一个文件调用它。
我需要做什么才能使这项工作做

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

编辑:
伙计们,请确保您的文件是ASCII编码。我已经创建了VS雷在默认情况下设置编码设置为UTF。

Guys, make sure your file is in ASCII encoding. I've created mine with VS which sets encoding to UTF by default.

推荐答案

更改您的批处理文件接收作为第一个参数$(PROJECTDIR)宏,然后更改PostBuild事件传递这个宏

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事件

PostBuild event

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

因为你的可执行文件(通常是Bin \\ Debug或RELEASE)的电流输出目录中执行postbuild事件您previous命令失败。你可以很容易地检查这增加了DIR命令重定向到的Result.txt在上面的例子

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

这篇关于的Visual Studio 2012,postbuild事件,bat文件没有创建新文件(不执行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:54