Comments (8)
Yeah its on my TODO list (in my head) - worry not!
from subprocess.h.
Quick question - it's not thread safe to inherit the environment of the parent and have the child process append to the environment of the parent process's environment.
Would it be ok for your usecases that the child process would not inherit the parent's environment, and instead if you wanted that as a user you'd have to pass along the environment variables yourself?
from subprocess.h.
That isn't the approach you would do. The process construction methods themselves allow you to pass an environment list, when you pass NULL they inherit by default the parent's environment. On windows this would be done by creating an environment block which is just a single block of string separated by null terminator characters. The end of the block must be an empty string (so the block end has two null termination characters.). On POSIX systems there's two ways, the easy way and the correct way, the easy way would be to just pass everything through /bin/env
as a string piping it to the actual process you create with execl
. The correct way however is to just specify a list of strings (terminated by an empty string) and use execvpe
instead. You do not have to call any of the setenv/putenv/etc
functions here.
from subprocess.h.
Right but the issue is that if you specify any environment variables at all then any environment variables that were set in the parent are not passed down.
I'm thinking of the case where you want to spawn a process but specify MY_SPECIAL_ENV_VAR
but also be able to read the PATH variable that was in the parent's context - the ways in which you do this in Wiindows/Linux are both inherently thread unsafe (you basically have to change the env of the parent process, spawn the child, then reset the env of the parent from my experience!).
from subprocess.h.
That isn't a useful operation. You can always read the parents's environment and copy them when you make your list before spawning the child process. This is actually required on Windows because Window's environment block does not permit you to override an environment variable that is already in the block. If you have FOO
already and then supply your own FOO
, it won't override. You have to meticulously hand craft the block not to contain duplicates. So it's not a 'safe' operation to blindly inherit the parent's environment and also accept user supplied ones that could conflict with what is already there. It's all or none as far as I understand. You eiher have all the parent's environment block upon child process construction or none of it.
from subprocess.h.
Gotya! Glad we had some back and forth on this, I'm pretty sure we're on the same page now
I think I'll add some option flags var that controls whether you inherit the parents environment or not - at present we are always inheriting which doesn't seem great!
from subprocess.h.
As the first part of this, I've created an MR that allows you to specify whether the parent environment should be inherited or not #6.
I'll then do a follow-up for setting individual environment variables.
from subprocess.h.
I also needed this feature on Linux and created a quick an dirty way to pass the env variables. The environment variables are ignored when the inherit option is set.
The approach that I took can be found here:
ha11owed@c95cf4e
As a note:
I was also considering creating a dedicated struct for all the parameters that need to be passed (to allow further extensibility in the future, for example should a current dir option also be added).
The MSVC part is missing, as I do not have access to a windows system right now.
from subprocess.h.
Related Issues (20)
- Support for "CREATE_NO_WINDOW" when launching process HOT 1
- Bug with empty environment HOT 6
- Issue with quotes in command line HOT 5
- "echo" -> "/bin/echo"
- Separate implementation from declaration HOT 2
- Lib is not spawning terminal instance to run a code HOT 1
- Verboser output of child in case of invalid/unknown command HOT 2
- Adding lifetime documentation HOT 3
- Feature Request: set the cwd for created processes HOT 3
- unable to read from stdout HOT 3
- Replacement of execvp for execv break compatibility. HOT 6
- MinGW support HOT 3
- Incorrect argument quoting on Windows HOT 3
- Do not execute `commandLineCombined` when we have only one command parameter HOT 4
- Should subprocess_option_search_user_path use the PATH from any environment to subprocess_create_ex? HOT 3
- posix_spawn does not build on Android & Emscripten (Wasm) HOT 1
- Unicode support on Windows? HOT 8
- Do you have a complete example of how to display the output of a command?
- Commands that need to be run as root/sudo fail silently
- Is it possible to hide the console window?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from subprocess.h.