Apache Ant 命令行参数不带双引号 - 这可能吗?

发布于 2024-08-08 16:54:09 字数 666 浏览 7 评论 0原文

今天我必须向 Apache Ant 文件添加一个任务。命令行应该是这样的。

myprogram --param1 --param2 path\somefile 2> path\logfile

问题是,如果我使用类似以下的内容,

<exec executable="$(myprogram)"
  <arg value="--param1">
  <arg value="--param2">
  <arg path="$(somefile)">
  <arg value="2>">
  <arg path="$(logfile)">
</exec>

所有参数都会被引用,所以命令看起来像这样:

myprogram "--param1" "--param2" "path\somefile" "2>" "path\logfile"

如果文件中有空格,这还不错,特别好/路径,但破坏了日志文件的管道(相反,程序认为有两个附加文件参数“2>”和“path\logfile”)。

我通过调用批处理脚本来解决这个问题,该脚本只需要文件作为参数,但我想知道:是否可以在没有这样的解决方法的情况下做到这一点?

Today I had to add a task to an Apache Ant file. The command line should have been something like

myprogram --param1 --param2 path\somefile 2> path\logfile

The problem with this was that if I used something like the following for this

<exec executable="$(myprogram)"
  <arg value="--param1">
  <arg value="--param2">
  <arg path="$(somefile)">
  <arg value="2>">
  <arg path="$(logfile)">
</exec>

all arguments were quoted, so the command looked like this:

myprogram "--param1" "--param2" "path\somefile" "2>" "path\logfile"

which is not bad and especially nice if you have spaces in your files/path, but destroys the pipe to the logfile (instead, the program thinks there are two additional file arguments "2>" and "path\logfile").

I worked around this by calling a batch script instead that only wants the files as parameters, but I wondered: Is it possible to do this without such a workaround?

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

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

发布评论

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

评论(4

弱骨蛰伏 2024-08-15 16:54:09

当您运行“myprogram --param1 --param2 path\somefile 2> path\logfile”时,程序的参数以“2>”结尾。文件重定向是 shell 的一项操作,不是在 ant 内部使用的。如果您查看 ant exec 任务 的文档,您会看到它支持通过 output 属性进行重定向。

When you run "myprogram --param1 --param2 path\somefile 2> path\logfile", the arguments to your program end at "2>". File redirection is an operation of your shell, which isn't being used from within ant. If you look at the docs for the ant exec task, you'll see that it supports redirection via the output attribute.

九厘米的零° 2024-08-15 16:54:09

您尝试过 吗?

Have you tried <arg line="..." />?

情深缘浅 2024-08-15 16:54:09

ant exec 任务有一个输出参数,您可以在其中指定日志文件,而无需命令行管道,并结合参数append 来确定是否应覆盖或附加输出文件。

The ant exec task has an output parameter where you could specify the log file without requiring the command line piping, combined with the parameter append to determine if the output file should be overwritten or appended to.

听闻余生 2024-08-15 16:54:09

我和主题启动者遇到了同样的问题。在 java 执行命令行上,我需要将源文件添加为单独的参数,而不是作为带有引号的一个参数。
我使用了 标记,但使用 作为 nullptr建议解决我的问题。

I had an equal problem as the topic starter did. On a java execution command line I needed to add source files as separate arguments, not as one argument with quotes around them.
I used the <arg value="..." /> tag, but using the <arg line="..." /> as nullptr suggested solved my problem.

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