Reputation: 35938
I would like to execute the following shell command
workon foo && python /path/to/bar.py --parm1 /path/p1 --parm2 /path/p2
I've tried running it like this
def sout = new StringBuffer(), serr = new StringBuffer()
def proc = ["/bin/zsh","-c"," workon foo", "&&", "python", "/path/to/bar.py", "--parm1", "/path/p1", "--parm2", "/path/p2"].execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
println "out> $sout err> $serr"
but I keep getting errors:
out> err> zsh:1: command not found: workon
I can execute this command from the terminal
Upvotes: 0
Views: 766
Reputation: 158
As @donkopotamus suggested it's likely that workon
is not in your path nor setup (via environment initialization) when zsh -c
is called. It's likely that you need a "login shell" to do this -but note that I don't use or know much about zsh
:)
Try running zsh -l -c COMMAND
.
In addition, the way you're calling zsh
with -c
, it can only process one command. Everything else will be treated as arguments to that command.
To use &&
, you'll have to assign this to proc
:
["/bin/zsh","-lc", "workon foo && python /path/to/bar.py ..."]
Notice that the argument to -c
is one string.
Upvotes: 2