<commit_before>package psdock

import (
	"exec"
	"os"
	"strings"
)

//SetEnvVars sets the environment variables for the launched process
func (c *Cmd) SetEnvVars(envVars string) {
	if envVars == "" {
		//We don't want to export any environment variable
		//But we can't leave c.Env empty, as exec.Run will export all the current
		//env vars. So we only export one unused environment variable
		c.Env.append("UNUSED")
	}
	for _, str := range strings.Split(envVars, " ") {
		//We want to export all the psdock's environment variables to the launched
		//process' environment
		if str == "$EXPORTALL" {
			if len(envVars) == 1 {
				//We want to export all the current environment variables, but nothing else.
				//We can therefore leave envVars empty.
				c.Env = make([]string, 0)
			} else {
				//We have new environment variables to export.
				//We have to manually copy all the current environment variables to c.Env
				c.Env = append(c.Env, os.Environ)
			}
			//We want to export a specific variable from the current environment
		} else if str[0] == '$' {
			valueOfEnv := os.Getenv(str[1:])
			if valueOfEnv == "" {
				log.Fatal("The variable", str[1:], "is not a defined environment variable")
			} else {
				c.Env.append([]string{str[1:], "=", valueOfEnv})
			}
			//str is already in the form "VAR1=value1"
		} else {
			c.Env.append(str)
		}<commit_msg>Modified the way environment variables are exported<commit_after>package psdock

import (
	"os"
	"os/exec"
	"strings"
)

//SetEnvVars sets the environment variables for the launched process
//Note:if we precise a variable already present in the user's environment,
//the value will be the one we have given.
//The $PATH variable is not empty by default. If we override it, the elements we
//provide will be appended to the default $PATH (/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin)
func SetEnvVars(c *exec.Cmd, envVars string) {
	//We first have to manually copy all the current environment variables to c.Env
	c.Env = append(c.Env, os.Environ()...)
	for _, str := range strings.Split(envVars, " ") {
		c.Env = append(c.Env, str)
{'fraction_non_alphanumeric': 0.1185149928605426, 'fraction_numerical': 0.0038077106139933364, 'mean_word_length': 3.397489539748954, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2294216', 'n_tokens_mistral': 716, 'n_tokens_neox': 653, 'n_words': 254}