Exec and ENVSET

Post Reply
tboyer
Posts: 68
Joined: Mon Aug 28, 2006 4:43 pm

Exec and ENVSET

Post by tboyer »

Having trouble setting path inside an exec using ENVSET. I must be missing something??

The script is located in /usr/local/bin.

First example works but last two do not.


<a name=thisworks public>
<$script='casperjs --version'>
<exec sh>
PATH=$PATH:/usr/local/bin
export PATH
$script
</exec>
<loop $ret>$ret</loop>
</a>

<a name=notworking1 public>
<$path = '/usr/bin:/usr/local/bin'>
<$script='casperjs --version'>
<exec ENVSET PATH=$path $script>
</exec>
$ret.err
</a>

<a name=notworking2 public>
<local path>
<$path = '/usr/bin:/usr/local/bin'>
<exec ENVSET PATH=/httpd/htdocs sh>
echo $PATH
</exec>
<loop $ret>
$ret
</loop>
</a>
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

Exec and ENVSET

Post by Kai »

In <notworking1>, note that <exec> does not space-separate the command line into args like the shell does (except under Windows, which does not have a concept of separate args at the OS level); this is so quotes/spaces/asterisks/etc. need not be escaped as in shell commands. So <exec "/bin/cmd option"> would try to exec the file `/bin/cmd option', not `/bin/cmd'. You're probably getting `Cannot exec `casperjs --version': No such file or directory' as the error: that message just prints what it thinks is the executable, not the args too, so seeing the arg(s) in there means they were glommed onto the exe. Use `<$script = "casperjs" "-version"><exec $script>...': make the command and each arg separate Vortex values.
Also, ENVSET affects the exec'd process environment, not Vortex's: so the search path for whatever you are <exec>ing is still Vortex's path, and is not affected by ENVSET. The ENVSET PATH will only affect what that exec'd `casperjs' itself tries to run.

In <notworking2>, in your `echo' statement, you're evaluating $PATH in Vortex, not the shell: so the script you are executing is not `echo $PATH' but `echo /whatever:/your:/vortex/script:/path/is:/not/what/ENVSET/set/it/too'. Use `echo $$PATH' instead (escape the dollar sign), so that the shell sees `echo $PATH'.

Same issue in <thisworks>: $PATH is evaluated in Vortex, not the shell, so you're running `PATH=/Vortex/path:/usr/local/bin' not `PATH=$PATH:/usr/local/bin'. It "works" because you have not set PATH (via ENVSET) before that point, so at that point the shell's $PATH is the same as Vortex's $PATH, so the net effect is the same. Again, escape var references in shell scripts that you want evaluated by the shell script instead of Vortex. (It also works with `<$script = "casperjs -version">' because you're letting the shell do its space-separation thing, because it is exec'ing casperjs, not Vortex. And again, `$script' is being evaluated in Vortex, not the shell.)
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Exec and ENVSET

Post by mark »

The problem that instigated this, /usr/local/bin not being in the web server's PATH, has been fixed. So
<exec "casperjs" "--version"></exec>
now works without fiddling the PATH in vortex.
tboyer
Posts: 68
Joined: Mon Aug 28, 2006 4:43 pm

Exec and ENVSET

Post by tboyer »

Great, thanks Mark.

Just for the record, would this have been a solution? Setting the Vortex path using vxcp before the exec?
<$path ='%EXEDIR%:%BINDIR%:%SYSLIBPATH%:/usr/bin:/usr/local/bin'>
<vxcp libpath $path>
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

Exec and ENVSET

Post by Kai »

No; <vxcp libpath> affects shared libs. <strfmt "%s:/usr/local/bin" $PATH><syscp setenv PATH $ret> would have added /usr/local/bin to the search path for the <exec>.
Post Reply