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

Add ability to launch a Process with a working directory #739

Closed
sleberknight opened this issue Jun 22, 2022 · 0 comments · Fixed by #741
Closed

Add ability to launch a Process with a working directory #739

sleberknight opened this issue Jun 22, 2022 · 0 comments · Fixed by #741
Assignees
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Milestone

Comments

@sleberknight
Copy link
Member

sleberknight commented Jun 22, 2022

Java's ProcessBuilder contains a lot more flexibility than we generally need when launching processes. However, a bunch of times recently I've needed to launch processes in the context of a specific working directory (e.g. git commands only make sense when in the project directory, and the same is true when running Maven commands).

This is to add an overloaded launch method in Processes and ProcessHelper that accepts a working directory in addition to the command. To avoid ambiguity with varargs parameters in the launch(String... command) methods, probably best to only overload the launch methods that accept a List<String>.

Since ProcessBuilder#directory(File) accepts a File argument, that's probably what these new methods should accept as well. We could also add two overloads, one that accepts a File and one that accepts Path, the latter we can easily convert to a File.

@sleberknight sleberknight added the new feature A new feature such as a new class, method, package, group of classes, etc. label Jun 22, 2022
@sleberknight sleberknight added this to the 2.1.0 milestone Jun 22, 2022
@sleberknight sleberknight self-assigned this Jun 22, 2022
sleberknight added a commit that referenced this issue Jun 23, 2022
* Add overloads of Processes#launch and ProcessHelper#launch that
  accept a File representing the working directory and a List that
  contains the command. Did not overload the launch methods that accept
  varargs because there can be ambiguity as to which method is called.
  For example, launch(null, "git", "status") is ambiguous since both
  launch(String...) and launch(File, String...) can apply and that
  would force ugly casts, etc.
* Update javadocs for Processes#waitForExit noting that we do not
  destroy the Process if the timeout occurs before the process exits

Closes #739
sleberknight added a commit that referenced this issue Jun 23, 2022
* Add overloads of Processes#launch and ProcessHelper#launch that
  accept a File representing the working directory and a List that
  contains the command. Did not overload the launch methods that accept
  varargs because there can be ambiguity as to which method is called.
  For example, launch(null, "git", "status") is ambiguous since both
  launch(String...) and launch(File, String...) can apply and that
  would force ugly casts, etc.
* Update javadocs for Processes#waitForExit noting that we do not
  destroy the Process if the timeout occurs before the process exits

Closes #739
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant