2

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:\tree
        └───test
            └───test

Can anyone tell me how to write a Ant script to print the tree structure in to a file?

2 Answers 2

4

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>
Sign up to request clarification or add additional context in comments.

1 Comment

I thought about suggesting cmd /c but thought it to be kinda redundant to invoke a shell just to call a console program. Didn't know that ant ignores PATHEXT :-)
1

(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"/>  

8 Comments

+1 tree is a regular command line application (tree.com) and not a built in command, so there is no need to call cmd
Well, I get the following error with the approach proposed: "Cannot run program "tree": CreateProcess error=2, The system cannot find the file specified."
You might have to change it a little. TREE [drive:][path] [/F] [/A] So executable="TREE ${basedir}"
Or even executable="TREE ${basedir} > ${basedir}\output.txt"
Thanks, but I get the same error "Cannot run program "tree C:\tree": CreateProcess error=2, The system cannot find the file specified."
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.