Setting the environment variable for a subprocess
Environment variables are just like any other variables that we have in our programming languages. They have a name and hold some value, which can be varied. These are used by the Linux/Windows commands or the shell/batch scripts to perform different operations. These are called environment variables because they are present in the environment of the process/command/script being executed. Generally, the process inherits the environment variables from the parent process.
They are accessed in different ways in different operating systems. In Windows, they are accessed as %ENVIRONMENT_VARIABLE_NAME%
, and in Unix-based operating systems, they are accessed as $ENVIRONMENT_VARIABLE_NAME
.
In Unix-based systems, you can use the printenv
command to print all the environment variables available for the process, and in Windows-based systems, you can use the SET
command.
In this recipe, we will pass some environment variables to our subprocess and make...