@@ -103,29 +103,34 @@ with a non-zero code)::
103
103
.. tip ::
104
104
105
105
.. versionadded :: 3.3
106
- The ability to define commands as array of arguments was introduced in Symfony 3.3.
106
+ The ability to define commands as arrays of arguments was introduced in
107
+ Symfony 3.3.
107
108
108
- When defining commands as arrays, its arguments are escaped for you and you should not
109
- escape them any further. You can also define commands as strings. When doing so, the
110
- command-line is parsed by the underlying shell of your operating system. This allows
111
- using e.g. stream redirections or conditional execution, but this is a lot less portable
112
- since each OS (esp. Windows vs Unix-like) handles escaping and parsing differently.
113
- When passing a command-line string, it becomes your responsibility to deal with this.
109
+ Using array of arguments is the recommended way to define commands. This
110
+ saves you from any escaping and allows sending signals seamlessly
111
+ (e.g. to stop processes before completion.)::
114
112
115
- Using array of arguments is the recommended way to define commands.
113
+ $process = new Process(array('/path/command', '--flag', 'arg 1', 'etc.'));
116
114
117
- If you need to define commands as strings, variable arguments should be passed as
118
- environment variables using the second argument of the `` run() ``, `` mustRun() `` or
119
- `` start() `` methods. Referencing them in command-line strings is OS-dependent::
115
+ If you need use stream redirections, conditional execution, or any other
116
+ features provided by the shell of your operating system, you can also define
117
+ commands as strings.
120
118
121
- // On Unix-like OSes
119
+ Please note that each OS provides a different syntax for their command-lines
120
+ so that it becomes your responsibility to deal with escaping and portability.
121
+
122
+ To provide any variable arguments to command-line string, pass them as
123
+ environment variables using the second argument of the ``run() ``,
124
+ ``mustRun() `` or ``start() `` methods. Referencing them is also OS-dependent::
125
+
126
+ // On Unix-like OSes (Linux, macOS)
122
127
$process = new Process('echo "$MESSAGE"');
123
128
124
129
// On Windows
125
- $process = new Process('echo % MESSAGE% ');
130
+ $process = new Process('echo ! MESSAGE! ');
126
131
127
132
// On both Unix-like and Windows
128
- $process->run(null, 'MESSAGE' => 'Something to output'] );
133
+ $process->run(null, array( 'MESSAGE' => 'Something to output') );
129
134
130
135
Getting real-time Process Output
131
136
--------------------------------
0 commit comments