Ian
Ian

Reputation: 287

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

Can I use & > in a groovy script executing shell commands? i.e.

/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

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


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)

Upvotes: 1

Views: 1477

Answers (1)

ataylor
ataylor

Reputation: 66059

Yes, you have to invoke the shell to background a task like that. A pure groovy solution would be to run the process with consumeProcessOutputStream:

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

Upvotes: 1

Related Questions