简体   繁体   English

我可以在执行Shell命令的常规脚本中使用&>吗?

[英]Can I use & > in a groovy script executing shell commands?

Can I use & > in a groovy script executing shell commands? 我可以在执行Shell命令的常规脚本中使用&>吗? ie

/someDir/myScripts/stop.sh $NAME & > /someDir/something/${NAME}/logs/stop.log

will just 只会

'/someDir/myScripts/stop.sh $NAME & > /someDir/something/${NAME}/logs/stop.log'.execute()

work or do i need to do something complicated? 工作还是我需要做一些复杂的事情?

cmd = "/someDir/myScripts/stop.sh $NAME & > /someDir/something/${NAME}/logs/stop.log"
['sh', '-c', cmd].execute();

may work better than the .execute() but i was just wondering if this is possible 可能比.execute()更好,但是我只是想知道这是否可能

if i cannot implement this i believe i can call another .sh with the command in that script but I was wondering if i could do it in the .groovy file 如果我不能实现这一点,我相信我可以在该脚本中使用该命令调用另一个.sh,但是我想知道是否可以在.groovy文件中进行操作


EDIT 编辑

the NAME is defined in my groovy program (also would like to know if i need the path) the program is just trying to stop something using a given stop.sh script (also stop the log of that program) 名称是在我的groovy程序中定义的(也想知道我是否需要路径),该程序只是尝试使用给定的stop.sh脚本来停止某事(也停止该程序的日志)

Yes, you have to invoke the shell to background a task like that. 是的,您必须调用Shell来使诸如此类的任务后台运行。 A pure groovy solution would be to run the process with consumeProcessOutputStream : 一个简单的常规解决方案将是使用消耗过程consumeProcessOutputStream运行该过程:

new File("/someDir/something/${NAME}/logs/stop.log").newOutputStream { log ->
    "/someDir/myScripts/stop.sh $NAME".execute().consumeProcessOutputStream(log)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM