Skip to content

Commit dee3a93

Browse files
jawshooahsds
authored andcommitted
Extract Windows cmd munging to private method
1 parent 515aec9 commit dee3a93

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/overcommit/subprocess.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ class << self
2525
# @option options [String] input string to pass via standard input stream
2626
# @return [Result]
2727
def spawn(args, options = {})
28-
if OS.windows?
29-
args.unshift('cmd.exe', '/c')
30-
end
28+
args = win32_prepare_args(args) if OS.windows?
3129

3230
process = ChildProcess.build(*args)
3331

@@ -57,9 +55,7 @@ def spawn(args, options = {})
5755
# Spawns a new process in the background using the given array of
5856
# arguments (the first element is the command).
5957
def spawn_detached(args)
60-
if OS.windows?
61-
args = %w[cmd.exe /c] + [args.join(' ')]
62-
end
58+
args = win32_prepare_args(args) if OS.windows?
6359

6460
process = ChildProcess.build(*args)
6561
process.detach = true
@@ -71,6 +67,12 @@ def spawn_detached(args)
7167

7268
private
7369

70+
# Necessary to run commands in the cmd.exe context.
71+
# Args are joined to properly handle quotes and special characters.
72+
def win32_prepare_args(args)
73+
%w[cmd.exe /c] + [args.join(' ')]
74+
end
75+
7476
# @param process [ChildProcess]
7577
# @return [Array<IO>]
7678
def assign_output_streams(process)

0 commit comments

Comments
 (0)