Fix 'system' to run cmd through shell

system modulefile command is intended to the command passed to it trough
shell, like done on compatibility version.

So update system procedure to find correct shell on the current platform
and run command through it.

Doing so, shell commands with backticks for instance are correctly run.

Fixes #205
This commit is contained in:
Xavier Delaruelle
2018-10-20 18:00:02 +02:00
parent 8defb257f0
commit 20aada54aa
5 changed files with 25 additions and 8 deletions

View File

@@ -444,10 +444,10 @@ the *modulefile* is being loaded.
**system** string
Pass *string* to the Tcl built-in command **exec**\ (n). For the **exec**\
(n) call **modulecmd.tcl** redirects stdout to stderr since stdout would
be parsed by the evaluating shell. The exit status of the executed command
is returned.
Run *string* command through shell. On Unix, command is passed to the
``/bin/sh`` shell whereas on Windows it is passed to ``cmd.exe``.
**modulecmd.tcl** redirects stdout to stderr since stdout would be parsed by
the evaluating shell. The exit status of the executed command is returned.
**uname** field

View File

@@ -2733,14 +2733,24 @@ proc uname {what} {
return $::unameCache($what)
}
proc system {mycmd args} {
reportDebug "$mycmd $args"
# run shell command
proc system {args} {
reportDebug $args
set mode [currentMode]
set status {}
if {$mode eq "load" || $mode eq "unload"} {
if {[catch {eval exec >&@stderr $mycmd $args}]} {
# run through the appropriate shell
if {[isWin]} {
set shell cmd.exe
set shellarg /c
} else {
set shell /bin/sh
set shellarg -c
}
if {[catch {exec >&@stderr $shell $shellarg [join $args]}]} {
# non-zero exit status, get it:
set status [lindex $::errorCode 2]
} else {

View File

@@ -31,3 +31,5 @@
setenv testsuite [system $env(TESTSUITEDIR)/systest]
setenv testsuite2 [system $env(TESTSUITEDIR)/systest 1 0 9]
setenv testsuite3 [system "$env(TESTSUITEDIR)/systest 1 0 9"]
setenv testsuite4 [system "$env(TESTSUITEDIR)/systest1 /path/to/`$env(TESTSUITEDIR)/systest1 dir`/file"]
setenv testsuite5 [system $env(TESTSUITEDIR)/systest1 /path/to/`$env(TESTSUITEDIR)/systest1 dir`/file]

View File

@@ -33,9 +33,11 @@ lappend ans [list set testsuite2 109]
lappend ans [list set testsuite3 109]
lappend ans [list set _LMFILES_ $modulefile]
lappend ans [list set LOADEDMODULES $module]
lappend ans [list set testsuite4 0]
lappend ans [list set testsuite 123]
lappend ans [list set testsuite5 0]
test_cmd "csh" "load $module" $ans
testouterr_cmd "csh" "load $module" $ans "str:/path/to/str:dir/file\nstr:/path/to/str:dir/file"
#
# Test a command returning 0 exit code

3
testsuite/systest1 Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/sh
echo "str:$1"