cea-hpc / modules

Environment Modules: provides dynamic modification of a user's environment
http://modules.sourceforge.net/
GNU General Public License v2.0
691 stars 106 forks source link

`source-sh` and `sh-to-mod` on Windows #534

Open xdelaruelle opened 3 weeks ago

xdelaruelle commented 3 weeks ago

I am using module framework on windows and I have downloaded windows package as well as install tclsh on my machine..

Is there a way to source a bat file or shell script on windows command prompt ?

source-sh bash /path/to/bash/script.sh 
or
source-sh bat /path/to/bat/script.bat
or
../../../modulecommand/modulecmd.tcl python sh-to-mod bash /path/to/bash/script.sh 
or
../../../modulecommand/modulecmd.tcl python sh-to-mod bat /path/to/bat/script.bat

Appreciate your inputs as I need to create a single modulefile for both linux and windows such that this is possible?

Originally posted by @jeevan4 in https://github.com/cea-hpc/modules/issues/399#issuecomment-2226428380

xdelaruelle commented 3 weeks ago

@jeevan4 bat scripts are not supported currently by source-sh modulefile command or sh-to-mod sub-command.

Even if I did not tried it, I think it should be possible to execute a bash script through source-sh or sh-to-mod on Windows. bash binary should be available in a directory listed in PATH or full path toward it should be provided as first argument of source-sh or sh-to-mod.

It would be interesting if you could tell us if you succeed or if you encounter specific issues.

To produce one modulefile that works on both Windows and Linux platform, you may also use the following Tcl conditional test to adapt execute depending on the platform (especially useful if both platforms do not share the exact same setup):

if {$::tcl_platform(platform) eq {windows}} {
    # code specific to the Windows platform
} else {
    # code specific to the Linux platform
}