Ant的exec在副本上返回错误

时间:2011-11-01 10:02:40

标签: java ant cmd exec

我需要连接两个文件。我为此目的使用Ant的exec,但是我收到以下错误。

production:
 [exec] Current OS is Windows 7
 [exec] Executing 'cmd' with arguments:
 [exec] 'copy /B destination\bin\installer.sh+destination.tar.gz Installer.bin'
 [exec]
 [exec] The ' characters around the executable and arguments are
 [exec] not part of the command.
 [exec] Microsoft Windows [Version 6.1.7600]
 [exec] Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
 [exec]

任务看起来像这样:

<target name="production" depends="tar" >
    <exec dir="${bin}"  executable="cmd">
        <arg line="'copy /B destination\bin\installer.sh+destination.tar.gz Installer.bin'"/>
    </exec>
</target>

如何解决此错误?

2 个答案:

答案 0 :(得分:4)

试试这个,

<target name="production" depends="tar" >
  <exec dir="${bin}" executable="cmd">
    <arg line="/C copy /B destination\bin\installer.sh+destination.tar.gz Installer.bin"/>
  </exec>
</target>

您需要让/C表示您正在将命令传递给cmd.exe

答案 1 :(得分:3)

您可以使用ant concat任务更轻松地执行此操作。不要忘记设置binary标志。作为奖励,这将超越Windows。