How to log the output from cmd tree command using Apache Ant exec task?
I am trying to log the output from cmd tree command using ant with the following:
<exec dir="${basedir}" executable="cmd" output="output.txt">
<arg value="tree" />
</exec>
However, I am seeing the following in the "output.txt":
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
When I run the command in the windows cmd:
C:\tree>tree
I get something like:
C:\tre开发者_如何学Ce
└───test
└───test
Can anyone tell me how to write a Ant script to print the tree structure in to a file?
You try to execute tree.com
. From the documentation of exec:
[...] In particular, if you do not put a file extension on the executable, only ".EXE" files are looked for, not ".COM", ".CMD" or other file types listed in the environment variable PATHEXT. That is only used by the shell.
You need to call tree.com
explicitely.
<exec dir="${basedir}" executable="tree.com" output="output.txt" />
Another way is to specify the /C
parameter of cmd
, that's what worked for me:
<exec dir="${basedir}" executable="cmd" output="output.txt">
<arg value="/C" />
<arg value="tree" />
</exec>
(Guessing here, I'm no Ant user)
If you would type
cmd tree
into the command prompt you also wouldn't see more than
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
What about just executing tree
?
<exec dir="${basedir}" executable="tree" output="output.txt"/>
精彩评论