Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Env vars handling #28

Closed
sebthom opened this issue Sep 11, 2021 · 6 comments
Closed

Env vars handling #28

sebthom opened this issue Sep 11, 2021 · 6 comments

Comments

@sebthom
Copy link

sebthom commented Sep 11, 2021

I am trying to migrate some code from java.lang.ProcessBuilder to ProcBuilder and have a few questions regarding env var handling.

  1. How can I control whether or not environment variables are inherited from the parent process?
    In java.lang.ProcessBuilder the default is to inherit all env vars and I can prevent this with a single call to:
    processBuilder.environment().clear()

  2. How can I set multiple env vars at once. Having to iterate over all vars and using the withVar(key, value) builder method defeats the purpose of fluent builder methods. So I am looking for a withVars(Map<String,String>) builder method or similar.

Thanks in advance!

@fleipold
Copy link
Owner

@sebthom thanks for your feedback!

Re 1: I overlooked this use case. It needs to be added. Probably something along the lines of procBuilder.clearEnvironment().

Re 2: I didn't have this use case (as most of the work pre-dates closures and streams as well as Map.of(Pair<K,V>…). It makes total sense to add withVars(Map<String, String>).

I am happy to add these things. I won't probably get to it until the mid of the week. Otherwise I am also happy to accept pull requests ;-).

@systemhalted
Copy link
Contributor

@fleipold I am working on (2) as I need it for my work. Hope to get a PR out soon.

@fleipold
Copy link
Owner

Thanks to @systemhalted 's PR a fix for the second issue is on its way to maven central and should show up as v2.7.0 on maven central soon. Re 1 @sebthom would adding a clearEnvironment method sound reasonable. It would be applied before any of the vars have been set.

@sebthom
Copy link
Author

sebthom commented Jan 23, 2022

That sounds reasonable!

fleipold added a commit that referenced this issue Jan 23, 2022
It looks really like I wrote this code with a Java 1.4 mindset. I might
have discarded the ProcessBuilder at the time, because it didn't solve the
whole problem (i.e. dealing with IO-streams). Now I got rid of the
code to deal with the ugly `String[]` they required.
fleipold added a commit that referenced this issue Jan 23, 2022
@fleipold
Copy link
Owner

Erledigt. 2.8.0 is on its way out to maven central.

@systemhalted
Copy link
Contributor

@fleipold Were you able to release the latest version to Maven Central?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants