Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduces the
Process.capturemethod that executes a command, captures its standard output, and returns it or raises an exception when the command fails (unsuccessful exit status).The method provides a safer replacement to the command operator (aka backticks) that has the following issues:
requires the command be executed in a shell, which in turn requires manual escapes and is prone to command injection;
doesn't check the exit status... while callers don't check it either, and errors get unnoticed.
The method is kept simple on purpose: it expects a command to always succeed (happy path) and to print to its standard output. Anything else (capture output + error, merge error -> output, act on error status) are better handled by
.newand.run.Example:
NOTE: please discuss the design in #7171.
This draft PR also provides a commit that refactors the compiler/std specs to replace all usages of the command operator and
shell: truearg, so we can evaluate the benefits of the change. It shall indeed be extracted into a follow-up PR.Closes #7171.
Related to #16614.