简体   繁体   English

ANT执行失败:java.io.IOException:无法运行程序“ cp”:java.io.IOException:error = 2,没有这样的文件或目录

[英]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.

相关问题 java.io.IOException:无法运行程序“/usr/bin/sh”:java.io.IOException:error=2,没有那个文件或目录 - java.io.IOException: Cannot run program “/usr/bin/sh”: java.io.IOException: error=2, No such file or directory java.io.IOException:无法运行程序“usr/bin/ffmpeg”:错误=2,没有那个文件或目录 - java.io.IOException: Cannot run program “usr/bin/ffmpeg ”: error=2, No such file or directory mencoder:java.io.IOException:error = 2,没有这样的文件或目录 - mencoder :java.io.IOException: error=2, No such file or directory java.io.IOException:error = 11 - java.io.IOException: error=11 java.io.IOException:无法运行程序“ sudo sh /etc/rc.d/init.d/jbossas7 restart”:error = 2,没有这样的文件或目录 - java.io.IOException: Cannot run program “sudo sh /etc/rc.d/init.d/jbossas7 restart”: error=2, No such file or directory hadoop无法分配内存java.io.IOException:错误= 12 - hadoop cannot allocate memory java.io.IOException: error=12 java.io.IOException:权限被拒绝无法在 Linux 中创建文件 - java.io.IOException: Permission denied cannot create file in Linux 构建失败,出现异常 java.io.IOException: Permission denied - Build failed with an exception java.io.IOException: Permission denied java.io.IOException:权限被拒绝但文件已创建 - java.io.IOException: Permission denied but file is created File.createNewFile()给出java.io.IOException:权限被拒绝 - File.createNewFile() gives java.io.IOException: Permission denied
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM