@@ -230,7 +230,7 @@ byteenv(env::Union{AbstractVector{Pair{T,V}}, Tuple{Vararg{Pair{T,V}}}}) where {
230
230
String[cstr (k* " =" * string (v)) for (k,v) in env]
231
231
232
232
"""
233
- setenv(command::Cmd, env; dir="" )
233
+ setenv(command::Cmd, env; dir)
234
234
235
235
Set environment variables to use when running the given `command`. `env` is either a
236
236
dictionary mapping strings to strings, an array of strings of the form `"var=val"`, or
@@ -239,11 +239,22 @@ existing environment, create `env` through `copy(ENV)` and then setting `env["va
239
239
as desired, or use `addenv`.
240
240
241
241
The `dir` keyword argument can be used to specify a working directory for the command.
242
+ `dir` defaults to the currently set `dir` for `command` (which is the current working
243
+ directory if not specified already).
242
244
"""
243
- setenv (cmd:: Cmd , env; dir= " " ) = Cmd (cmd; env= byteenv (env), dir= dir)
244
- setenv (cmd:: Cmd , env:: Pair{<:AbstractString} ...; dir= " " ) =
245
+ setenv (cmd:: Cmd , env; dir= cmd . dir ) = Cmd (cmd; env= byteenv (env), dir= dir)
246
+ setenv (cmd:: Cmd , env:: Pair{<:AbstractString} ...; dir= cmd . dir ) =
245
247
setenv (cmd, env; dir= dir)
246
- setenv (cmd:: Cmd ; dir= " " ) = Cmd (cmd; dir= dir)
248
+ setenv (cmd:: Cmd ; dir= cmd. dir) = Cmd (cmd; dir= dir)
249
+
250
+ # split environment entry string into before and after first `=` (key and value)
251
+ function splitenv (e:: String )
252
+ i = findnext (' =' , e, 2 )
253
+ if i === nothing
254
+ throw (ArgumentError (" malformed environment entry" ))
255
+ end
256
+ e[1 : prevind (e, i)], e[nextind (e, i): end ]
257
+ end
247
258
248
259
"""
249
260
addenv(command::Cmd, env...; inherit::Bool = true)
@@ -262,7 +273,7 @@ function addenv(cmd::Cmd, env::Dict; inherit::Bool = true)
262
273
merge! (new_env, ENV )
263
274
end
264
275
else
265
- for (k, v) in split .(cmd. env, " = " )
276
+ for (k, v) in splitenv .(cmd. env)
266
277
new_env[string (k):: String ] = string (v):: String
267
278
end
268
279
end
@@ -277,7 +288,7 @@ function addenv(cmd::Cmd, pairs::Pair{<:AbstractString}...; inherit::Bool = true
277
288
end
278
289
279
290
function addenv (cmd:: Cmd , env:: Vector{<:AbstractString} ; inherit:: Bool = true )
280
- return addenv (cmd, Dict (k => v for (k, v) in split .(env, " = " )); inherit)
291
+ return addenv (cmd, Dict (k => v for (k, v) in splitenv .(env)); inherit)
281
292
end
282
293
283
294
(& )(left:: AbstractCmd , right:: AbstractCmd ) = AndCmds (left, right)
0 commit comments