@@ -96,7 +96,10 @@ function QuotedString {
96
96
[string ] $Item
97
97
)
98
98
99
- # We surround the string with double quotes, in order to preserve its contents.
99
+ # We surround the string with double quotes, in order to preserve its contents as
100
+ # only one command arg.
101
+ # This is needed because PowerShell will consider a new argument when it sees a
102
+ # space char.
100
103
if (-not $Item.StartsWith (" `" " ) -and $Item.Contains (" " )) {
101
104
" `" $Item `" "
102
105
}
@@ -110,14 +113,18 @@ $ErlangParams = New-Object Collections.Generic.List[String]
110
113
$BeforeExtras = New-Object Collections.Generic.List[String ]
111
114
$AllOtherParams = New-Object Collections.Generic.List[String ]
112
115
116
+ $RunErlPipe = $null
117
+ $RunErlLog = $null
118
+
113
119
for ($i = 0 ; $i -lt $Args.Count ; $i ++ ) {
114
120
$private :Arg = $Args [$i ]
115
121
116
122
switch ($Arg ) {
117
123
{ $_ -in @ (" -e" , " -r" , " -pr" , " -pa" , " -pz" , " --eval" , " --remsh" , " --dot-iex" , " --dbg" ) } {
118
124
$private :NextArg = $Args [++ $i ] | NormalizeArg | QuotedString
119
125
120
- $ElixirParams.Add (" $Arg $NextArg " )
126
+ $ElixirParams.Add ($Arg )
127
+ $ElixirParams.Add ($NextArg )
121
128
122
129
break
123
130
}
@@ -139,7 +146,8 @@ for ($i = 0; $i -lt $Args.Count; $i++) {
139
146
}
140
147
141
148
" --cookie" {
142
- $ErlangParams.Add (" -setcookie $ ( $Args [++ $i ]) " )
149
+ $ErlangParams.Add (" -setcookie" )
150
+ $ErlangParams.Add ($Args [++ $i ])
143
151
break
144
152
}
145
153
@@ -149,44 +157,47 @@ for ($i = 0; $i -lt $Args.Count; $i++) {
149
157
}
150
158
151
159
" --name" {
152
- $ErlangParams.Add (" -name $ ( $Args [++ $i ]) " )
160
+ $ErlangParams.Add (" -name" )
161
+ $ErlangParams.Add ($Args [++ $i ])
153
162
break
154
163
}
155
164
156
165
" --sname" {
157
- $ErlangParams.Add (" -sname $ ( $Args [++ $i ]) " )
166
+ $ErlangParams.Add (" -sname" )
167
+ $ErlangParams.Add ($Args [++ $i ])
158
168
break
159
169
}
160
170
161
171
" --boot" {
162
- $ErlangParams.Add (" -boot $ ( $Args [++ $i ]) " )
172
+ $ErlangParams.Add (" -boot" )
173
+ $ErlangParams.Add ($Args [++ $i ])
163
174
break
164
175
}
165
176
166
177
" --erl-config" {
167
- $ErlangParams.Add (" -config $ ( $Args [++ $i ]) " )
178
+ $ErlangParams.Add (" -config" )
179
+ $ErlangParams.Add ($Args [++ $i ])
168
180
break
169
181
}
170
182
171
183
" --vm-args" {
172
- $ErlangParams.Add (" -args_file $ ( $Args [++ $i ]) " )
184
+ $ErlangParams.Add (" -args_file" )
185
+ $ErlangParams.Add ($Args [++ $i ])
173
186
break
174
187
}
175
188
176
189
" --logger-otp-reports" {
177
190
$private :TempVal = $Args [$i + 1 ]
178
191
if ($TempVal -in @ (" true" , " false" )) {
179
-
180
- $ErlangParams.Add (" -logger handle_otp_reports $ ( $Args [++ $i ]) " )
192
+ $ErlangParams.AddRange ([string []]@ (" -logger" , " handle_otp_reports" , $Args [++ $i ]))
181
193
}
182
194
break
183
195
}
184
196
185
197
" --logger-sasl-reports" {
186
198
$private :TempVal = $Args [$i + 1 ]
187
199
if ($TempVal -in @ (" true" , " false" )) {
188
-
189
- $ErlangParams.Add (" -logger handle_sasl $ ( $Args [++ $i ]) " )
200
+ $ErlangParams.AddRange ([string []]@ (" -logger" , " handle_sasl" , $Args [++ $i ]))
190
201
}
191
202
break
192
203
}
@@ -210,23 +221,28 @@ for ($i = 0; $i -lt $Args.Count; $i++) {
210
221
break
211
222
}
212
223
213
- " +elixirc" { $ElixirParams.Add (" +elixirc" ); break }
224
+ " +elixirc" {
225
+ $ElixirParams.Add (" +elixirc" )
226
+ break
227
+ }
214
228
215
229
" --rpc-eval" {
216
230
$private :Key = $Args [++ $i ]
217
231
$private :Value = $Args [++ $i ]
218
232
219
233
if ($null -eq $Key ) {
220
234
Write-Error " --rpc-eval: NODE must be present"
221
- exit
235
+ exit 1
222
236
}
223
237
224
238
if ($null -eq $Value ) {
225
239
Write-Error " --rpc-eval: COMMAND for the '$Key ' node must be present"
226
- exit
240
+ exit 1
227
241
}
228
242
229
- $ElixirParams.Add (" --rpc-eval $Key $ ( QuotedString $Value ) " )
243
+ $ElixirParams.Add (" --rpc-eval" )
244
+ $ElixirParams.Add ($Key )
245
+ $ElixirParams.Add (" $ ( QuotedString $Value ) " )
230
246
break
231
247
}
232
248
@@ -236,23 +252,39 @@ for ($i = 0; $i -lt $Args.Count; $i++) {
236
252
237
253
if ($null -eq $Key ) {
238
254
Write-Error " --boot-var: VAR must be present"
239
- exit
255
+ exit 1
240
256
}
241
257
242
258
if ($null -eq $Value ) {
243
259
Write-Error " --boot-var: Value for the '$Key ' var must be present"
244
- exit
260
+ exit 1
245
261
}
246
262
247
- $ErlangParams.Add (" -boot_var $Key $ ( QuotedString $Value ) " )
263
+ $ElixirParams.Add (" -boot_var" )
264
+ $ElixirParams.Add ($Key )
265
+ $ElixirParams.Add (" $ ( QuotedString $Value ) " )
248
266
break
249
267
}
250
268
251
269
" --pipe-to" {
252
- $private :Key = $Args [++ $i ]
253
- $private :Value = $Args [++ $i ]
270
+ $RunErlPipe = $Args [++ $i ]
271
+ $RunErlLog = $Args [++ $i ]
272
+
273
+ if ($null -eq $RunErlPipe ) {
274
+ Write-Error " --pipe-to: PIPEDIR must be present"
275
+ exit 1
276
+ }
277
+
278
+ if ($null -eq $RunErlLog ) {
279
+ Write-Error " --pipe-to: PIPELOG must be present"
280
+ exit 1
281
+ }
282
+
283
+ if ($RunErlPipe.EndsWith (" /" ) -or $RunErlLog.EndsWith (" /" )) {
284
+ Write-Error " --pipe-to: PIPEDIR and PIPELOG must not end with a slash"
285
+ exit 1
286
+ }
254
287
255
- Write-Warning " --pipe-to: Option is not yet supported. Ignoring $Key $Value "
256
288
break
257
289
}
258
290
@@ -262,7 +294,6 @@ for ($i = 0; $i -lt $Args.Count; $i++) {
262
294
$AllOtherParams.Add ($Normalized )
263
295
}
264
296
else {
265
- # We add quotes to preserve contents, since the quotes are removed by Powershell.
266
297
$AllOtherParams.Add (" $ ( QuotedString $Normalized ) " )
267
298
}
268
299
break
@@ -275,16 +306,16 @@ for ($i = 0; $i -lt $Args.Count; $i++) {
275
306
if ($PSStyle.OutputRendering -ne " PlainText" ) {
276
307
# TODO: find a way to detect if the term is interactive on Windows.
277
308
if ($IsWindows -or (test - t 1 - a - t 2 )) {
278
- $BeforeExtras.Insert (0 , " -elixir ansi_enabled true" )
309
+ $BeforeExtras.InsertRange (0 , [ string []] @ ( " -elixir" , " ansi_enabled" , " true" ) )
279
310
}
280
311
}
281
312
282
313
if ($null -eq $UseIEx ) {
283
- $BeforeExtras.Insert (0 , " -s elixir start_cli" )
314
+ $BeforeExtras.InsertRange (0 , [ string []] @ ( " -s" , " elixir" , " start_cli" ) )
284
315
}
285
316
286
- $BeforeExtras.Insert (0 , " -pa $ ( Join-Path $ScriptPath - ChildPath " ../lib/elixir/ebin" ) " )
287
- $BeforeExtras.Insert (0 , " -noshell -elixir_root $ ( Join-Path $ScriptPath - ChildPath " ../lib" ) " )
317
+ $BeforeExtras.InsertRange (0 , [ string []] @ ( " -pa" , " $ ( Join-Path $ScriptPath - ChildPath " ../lib/elixir/ebin" ) " ) )
318
+ $BeforeExtras.InsertRange (0 , [ string []] @ ( " -noshell" , " -elixir_root" , " $ ( Join-Path $ScriptPath - ChildPath " ../lib" ) " ) )
288
319
289
320
# One MAY change ERTS_BIN= but you MUST NOT change
290
321
# ERTS_BIN=$ERTS_BIN as it is handled by Elixir releases.
@@ -303,8 +334,6 @@ $AllParams.Add("-extra")
303
334
$AllParams.AddRange ($ElixirParams )
304
335
$AllParams.AddRange ($AllOtherParams )
305
336
306
- $ParamsPart = [string ]::Join(" " , $AllParams )
307
-
308
337
$BinSuffix = " "
309
338
310
339
if ($IsWindows ) {
@@ -317,10 +346,34 @@ if ($ERTS_BIN) {
317
346
$BinPath = Join-Path - Path $ERTS_BIN - ChildPath $BinPath
318
347
}
319
348
349
+ if ($null -eq $RunErlPipe ) {
350
+ $ParamsPart = [string ]::Join(" " , $AllParams )
351
+ }
352
+ else {
353
+ $private :OrigBinPath = $BinPath
354
+ $ErlExec = " run_erl"
355
+ $BinPath = " $ErlExec$BinSuffix "
356
+
357
+ if ($ERTS_BIN ) {
358
+ $BinPath = Join-Path - Path $ERTS_BIN - ChildPath $BinPath
359
+ }
360
+
361
+ $AllParams.Insert (0 , $OrigBinPath )
362
+
363
+ # We only scape double-quotes because the command will be surrounded by double-quotes.
364
+ $private :Escaped = $AllParams | ForEach-Object - Process { $_ -replace " `" " , " \$&" }
365
+
366
+ $ParamsPart = " -daemon `" $RunErlPipe /`" `" $RunErlLog /`" `" $ ( [string ]::Join(" " , $Escaped )) `" "
367
+ }
368
+
320
369
if ($Env: ELIXIR_CLI_DRY_RUN ) {
321
370
Write-Host " $BinPath $ParamsPart "
322
371
}
323
372
else {
324
- $Output = Start-Process - FilePath $BinPath - ArgumentList $ParamsPart - NoNewWindow - Wait - PassThru
373
+ if ($RunErlPipe ) {
374
+ $null = New-Item - Path " ." - ItemType " directory" - Name " $RunErlPipe " - Force
375
+ $null = New-Item - Path " ." - ItemType " directory" - Name " $RunErlLog " - Force
376
+ }
377
+ $Output = Start-Process - FilePath $BinPath - ArgumentList " $ParamsPart " - NoNewWindow - Wait - PassThru
325
378
exit $Output.ExitCode
326
379
}
0 commit comments