[英]ANT Execute failed: java.io.IOException: Cannot run program “cp ”: java.io.IOException: error=2, No such file or directory
I'm trying to use ANT to copy files from one directory to another directory on Linux. 我正在尝试使用ANT将文件从Linux上的一个目录复制到另一个目录。
Firstly I used copy task, it works fine but the file mode is not preserved. 首先,我使用了复制任务,它可以正常工作,但未保留文件模式。 Then I changed to use , and that's where I got stuck.
然后我更改为使用,这就是我遇到的问题。
My target is like: 我的目标是:
<target name="test">
<echo message="${basedir}"/>
<exec executable="cp " os="Linux" spawn="yes">
<arg line="-p"/>
<arg line="/tmp/jmap.dat"/>
<arg line="/tmp/jmap.dat1"/>
</exec>
</target>
The output I got is: test: [echo] /Users/bpel/mywork/projects/bpel-psr/utils 我得到的输出是:测试:[echo] / Users / bpel / mywork / projects / bpel-psr / utils
/utils/build.xml:38: Execute failed: java.io.IOException: Cannot run program "cp ": java.io.IOException: error=2, No such file or directory
/utils/build.xml:38:执行失败:java.io.IOException:无法运行程序“ cp”:java.io.IOException:error = 2,没有这样的文件或目录
I also tried something like: 我也尝试过类似的方法:
<exec executable="cp -p /tmp/jmap.dat /tmp/jmap.dat1"/>
and it doesn't work either, it seems cannot find cp
command, but if I manually run cp -p /tmp/jmap.dat /tmp/jmap.dat1
, it just works fine. 而且也不起作用,似乎找不到
cp
命令,但是如果我手动运行cp -p /tmp/jmap.dat /tmp/jmap.dat1
,它就可以正常工作。
I've been googling around and found no help. 我一直在四处搜寻,没有发现任何帮助。
The similiar question on stackoverflow doesn't solve my problem: 关于stackoverflow的类似问题不能解决我的问题:
You have a space after the cp
command: cp
命令后有一个空格:
<exec executable="cp " os="Linux" spawn="yes">
That's telling it run a command called "cp "
(with the space). 这表明它运行了一个名为
"cp "
的命令(带有空格)。 This is confirmed by the error message: 错误消息确认了这一点:
Cannot run program
"cp "
无法运行程序
"cp "
In fact, the answer is in the subject of the question :) 实际上,答案是在问题的主题中:)
Take the space out, it should be fine: 删除空间,应该没问题:
<exec executable="cp" os="Linux" spawn="yes">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.