蚂蚁exec
任务有哪些可以用来告诉Ant哪里输出变为输出属性。 我用它来输出重定向到一个文件中。 问题是,如果我不做点什么的输出,即蚂蚁版画是没有太大的帮助的东西 - 这是不完整的。
有什么方法设置输出属性的System.out
?
蚂蚁exec
任务有哪些可以用来告诉Ant哪里输出变为输出属性。 我用它来输出重定向到一个文件中。 问题是,如果我不做点什么的输出,即蚂蚁版画是没有太大的帮助的东西 - 这是不完整的。
有什么方法设置输出属性的System.out
?
当执行与的蚂蚁一个批处理文件, apply
或exec
在Windows的任务,我发现有一些地方的输出和错误不被捕获蚂蚁的特殊情况。 (例如:如果你调用一个批处理文件,依次调用其他命令(如node.exe
),然后从孩子的标准输出和stderror node.exe
。过程中丢失)
我花了很长时间试图调试此! 看来,该批处理文件的输出和错误被捕获,但命令由批处理文件调用不知何故没有蚂蚁看见。 (也许是因为它们是独立的子进程)。 使用output
和error
的属性上述建议没有帮助,因为只有一些 stdout和/或标准错误被捕获。
我想出了( 黑客攻击 )的解决方案是在命令的末尾添加这些参数:
<!--Next arg: forces node's stderror and stdout to a temporary file-->
<arg line=" > _tempfile.out 2<&1"/>
<!--Next arg: If command exits with an error, then output the temporary file to stdout, -->
<!--delete the temporary file and finally exit with error level 1 so that -->
<!--the apply task can catch the error if @failonerror="true" -->
<arg line=" || (type _tempfile.out & del _tempfile.out & exit /b 1)"/>
<!--Next arg: Otherwise, just type the temporary file and delete it-->
<arg line=" & type _tempfile.out & del _tempfile.out &"/>
因为这个技巧只适用于Windows,记得要加@osfamily="windows"
的apply
或exec
任务。 而对于`@ osfamily =“UNIX”等,但没有这些额外的参数创建类似的任务(一个或多个)。
输出exec
不会去到标准输出,除非你指定的output
属性。
如果要输出到System.out,后来干脆不指定“输出”属性。 如果您想重定向到一个文件并打印到System.out,你可以使用三通命令,将输出重定向到一个指定的文件并且还回显到标准输出...我不知道,如果Windows支持“三通”或等效的。
也许你想看看error
, logError
和errorproperty
的属性EXEC过任务。 这些处理从exec'd工艺标准错误流的处理。 有可能是有用的信息有被开小差出于某种原因 - 可能占你看到的不完备性。
但是,如果exec'd过程决定关闭stdout或stderr和其他地方给他们 - 有一点你可以做。
我已经面临着类似的问题:命令执行的输出被抑制。 也许这是运行时,副作用cmd
在WinXP下(I一个使用maven-antrun-plugin
)。 无论如何设置output="con"
制定了完美:
<configuration>
<target>
<exec executable="cmd" output="con">
<arg value="/c" />
<arg value="..." />
</exec>
</target>
</configuration>
利用Ant和Gruntjs工作:
对于任何试图让这个使用Gruntjs工作。 我能得到它通过执行以下操作( 结合darcyparker的答案 )工作。
在我的Ant构建文件:
<target description="run grunt js tasks" name="grunt">
<exec dir="/path/to/grunt" executable="cmd" failonerror="true">
<arg value="/c"/>
<arg value="jshint.bat"/> // I broke each task into it's own exec
<arg line=" > jshint.log 2<&1"/>
<arg line=" || (type jshint.log & del jshint.log & exit /b 1)"/>
<arg line=" & type jshint.log & del jshint.log &"/>
</exec>
<exec dir="/path/to/grunt" executable="cmd" failonerror="true">
// another grunt task (IE: uglify, cssmin, ect..)
</exec>
</target>
jshint.bat
@echo off
pushd "C:\path\to\grunt\"
@ECHO _____________________________________________
@ECHO GRUNT JSHINT
@ECHO _____________________________________________
grunt jshint --stack >>jshint.log
注:路径的呼噜声会在您Gruntfile.js所在。 另外请注意,我不得不开始创建日志文件( 把它与darcyparker的回答工作 ),这将来自特定任务输出的堆栈跟踪。 那么这会给我从哪里我打电话给我的Ant目标任务堆栈输出的呼噜声。
最后请注意, pushd "C:\path\to\grunt\"
,如果你的蝙蝠文件在同一目录下不会necissary Gruntfile.js
。
我正经历着这种相同的问题,试图让构建过程中蚂蚁失败后噶测试失败的故意,并以“咕噜测试”执行它们。
刚刚添加之前“咕噜测试” / C,和它的工作就像一个魅力
<target name="unittest">
<echo>*** KARMA UNIT TESTING ***</echo>
<exec dir="api_ui" executable="cmd" osfamily="windows" logError="yes" failonerror="true">
<arg value="/c grunt test"/>
</exec>
</target>