Groovy 在不同的工作目录中执行shell进程时,是否可以使用通配符?

Groovy 在不同的工作目录中执行shell进程时,是否可以使用通配符?,groovy,Groovy,这是我当前的目录结构 / <-- current working Dir /php/ file1.php file2.php file3.txt 但是我一直得到cp:cannot stat*.php”:没有这样的文件或目录,我已经验证了文件存在,并且验证了我当前的工作目录 如果我执行log.info'ls-la'.execute(null,新文件('./php/'))我会看到php和.txt文件 这似乎是一个长期的尝试,但我认为在指定的工作目录中执行命令时使用

这是我当前的目录结构

/ <-- current working Dir
  /php/
    file1.php
    file2.php
    file3.txt
但是我一直得到
cp:cannot stat*.php”:没有这样的文件或目录
,我已经验证了文件存在,并且验证了我当前的工作目录

如果我执行
log.info'ls-la'.execute(null,新文件('./php/'))
我会看到php和.txt文件

这似乎是一个长期的尝试,但我认为在指定的工作目录中执行命令时使用通配符可能会有错误,除非我缺少什么


我正在使用groovy 1.7.5

这个版本适合我,请试用一下:

    #!/usr/bin/env groovy

    command = ["sh", "-c", "cp -f *.php /tmp/"]
    def cpProc = command.execute(null, new File('./php/'))
    cpProc.waitFor()
    print 'current exitvalue :' + cpProc.exitValue() + '\n'
    print 'current proc out : ' + cpProc.text + '\n'

    print 'ls -la'.execute(null, new File('/tmp/')).text
关于此问题的第一个答案解释了您的版本不起作用的原因:

    #!/usr/bin/env groovy

    command = ["sh", "-c", "cp -f *.php /tmp/"]
    def cpProc = command.execute(null, new File('./php/'))
    cpProc.waitFor()
    print 'current exitvalue :' + cpProc.exitValue() + '\n'
    print 'current proc out : ' + cpProc.text + '\n'

    print 'ls -la'.execute(null, new File('/tmp/')).text