You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::process::Command;use std::env;fnmain(){// Create a command to echo $foo.letmut c = Command::new("bash");
c.arg("-c").arg("echo $foo");// Set an unrelated variable. This caches the current environment.
c.env("UNRELATED_VARIABLE","junk");// Define $foo in the parent. This has no effect on the child,// because of the line above!
env::set_var("foo","FOO IS DEFINED!!!");
c.spawn().unwrap();}
This program will run echo $foo, which prints an empty line because $foo is not defined in the child. But if we delete the line that sets $UNRELATED_VARIABLE and run again, we see FOO IS DEFINED!!! in the child's output.
The problem is that (at least in the unix implementation) the init_env_map function caches the parent's environment the first time it's called. My preferred behavior would be that Command never caches anything from the parent, and instead reads the environment at the time the child is spawned. Does anyone know of code relying on the current behavior?
The text was updated successfully, but these errors were encountered:
An example:
This program will run
echo $foo
, which prints an empty line because$foo
is not defined in the child. But if we delete the line that sets$UNRELATED_VARIABLE
and run again, we seeFOO IS DEFINED!!!
in the child's output.The problem is that (at least in the unix implementation) the
init_env_map
function caches the parent's environment the first time it's called. My preferred behavior would be that Command never caches anything from the parent, and instead reads the environment at the time the child is spawned. Does anyone know of code relying on the current behavior?The text was updated successfully, but these errors were encountered: