如何使用 Apache Ant exec 任务记录 cmd tree 命令的输出?

发布于 2024-08-31 14:09:38 字数 554 浏览 1 评论 0原文

我正在尝试使用 ant 记录 cmd tree 命令的输出,内容如下:

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

但是,我在“output.txt”中看到以下内容:

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

当我在 Windows cmd 中运行命令时:

    C:\tree>tree 

我得到类似以下内容:

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

谁能告诉我我如何编写一个 Ant 脚本来将树结构打印到文件中?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

格子衫的從容 2024-09-07 14:09:38

您尝试执行tree.com。来自 exec 的文档

[...] 特别是,如果您不放置
仅可执行文件的文件扩展名
查找“.EXE”文件,而不是
“.COM”、“.CMD”或其他文件类型
列在环境变量中
路径文本。这仅由
外壳。

您需要明确调用tree.com

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

另一种方法是指定 cmd/C 参数,这对我有用:

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

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>
似梦非梦 2024-09-07 14:09:38

(这里猜测,我不是 Ant 用户)

如果您在命令提示符中键入内容

cmd tree

,您也不会看到除了

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

仅执行 tree 怎么样?

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

(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"/>  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文