How to record output of cmd tree command using Apache Ant exec task?

I am trying to log the output of a cmd tree command using ant with the following:

    <exec dir="${basedir}" executable="cmd" output="output.txt">
        <arg value="tree" />
    </exec>

      

However, in "output.txt" I see the following:

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

      

When I run the command in the cmd window:

    C:\tree>tree 

      

I am getting something like:

    C:\tree
        └───test
            └───test

      

Can anyone tell me how to write an ant script to print the tree structure to a file?

+2


a source to share


2 answers


You are trying to execute tree.com

. From exec documentation :

[...] Specifically, if you don't have a file extension on the executable, only ".EXE" files are searched, not ".COM", ".CMD" or other file types listed in the PATHEXT environment variable. This is only used by the shell.

You must explicitly name tree.com

.

<exec dir="${basedir}" executable="tree.com" output="output.txt" />

      




Another way is to specify a parameter /C

cmd

, which worked for me:

<exec dir="${basedir}" executable="cmd" output="output.txt">
    <arg value="/C" />
    <arg value="tree" />
</exec>

      

+4


a source


(Assuming I am not an Ant user)

If you type

cmd tree

      

on the command line you also won't see anymore



Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

      

How about fulfillment tree

?

<exec dir="${basedir}" executable="tree" output="output.txt"/>  

      

+1


a source







All Articles