Skip to content

Expand ProcessBuilder to provide methods for adding flags and options as well #5451

boombatower opened this Issue Sep 7, 2012 · 4 comments

3 participants


I wrote my own CommandBuilder class that builds a command string. The class provides:

  • addArgument($argument) - command argument1 argument2
  • addOption($option, $value) - command --option1 value --option2 value
  • addFlag($flag) - command --flag1 --flag2

The following format options were also provided to allow for various preferences or requirements.

  'single_dash' => FALSE,  // all flags/options have single dash instead of double, normally only single letter flags have single dash. useful for some command line interfaces like java -jar ...
  'option_equal' => FALSE, // add equal between option and value, --option=value
  'escape' => TRUE, // wrap each value using escapeshellarg()
  'newline' => FALSE, // print each part of the command on newline for readability

If this seems like a reasonable addition I will go ahead and merge into ProcessBuilder and make a pull request.


Also seems like doing something like CommandBuilder that can be passed to Process constructor is a better design since it allows people to extend the Process class and use ProcessBuilder with their class. Or perhaps split about the command building into a command builder class and allow them to be build separately with the command builder defining a __toString(). Building the command string is the hard part or the part that can benefit most from a builder, rather than setting booleans.


Although looking at Process class, everything is private...seems like should be protected.

pscheit commented Jun 3, 2013

+1 for that and i would love it as a CommandBuilder, too. I have code in preparation for this. Are you still processing it?

Symfony member
fabpot commented Mar 13, 2014

Closing this issue as this would complexify the component too much for no real added benefits.

@fabpot fabpot closed this Mar 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.