1
1
var childProcess = require ( 'child_process' ) ,
2
+ os = require ( 'os' ) ,
2
3
fs = require ( 'fs' ) ,
3
4
path = require ( 'path' ) ,
4
5
running = require ( 'is-running' ) ,
@@ -7,11 +8,12 @@ var childProcess = require('child_process'),
7
8
psTree = require ( 'ps-tree' ) ;
8
9
9
10
function Local ( ) {
11
+ this . windows = os . platform ( ) . match ( / m s w i n | m s y s | m i n g w | c y g w i n | b c c w i n | w i n c e | e m c | w i n 3 2 / i) ;
10
12
this . pid = undefined ;
11
13
this . isProcessRunning = false ;
12
14
this . retriesLeft = 5 ;
13
15
this . key = process . env . BROWSERSTACK_ACCESS_KEY ;
14
- this . logfile = path . join ( process . cwd ( ) , 'local.log' ) ;
16
+ this . logfile = this . sanitizePath ( path . join ( process . cwd ( ) , 'local.log' ) ) ;
15
17
this . opcode = 'start' ;
16
18
this . exitCallback ;
17
19
@@ -124,7 +126,7 @@ function Local(){
124
126
case 'folder' :
125
127
if ( value ) {
126
128
this . folderFlag = '-f' ;
127
- this . folderPath = value ;
129
+ this . folderPath = this . sanitizePath ( value ) ;
128
130
}
129
131
break ;
130
132
@@ -157,7 +159,7 @@ function Local(){
157
159
case 'logfile' :
158
160
case 'logFile' :
159
161
if ( value )
160
- this . logfile = value ;
162
+ this . logfile = this . sanitizePath ( value ) ;
161
163
break ;
162
164
163
165
case 'parallelRuns' :
@@ -167,7 +169,7 @@ function Local(){
167
169
168
170
case 'binarypath' :
169
171
if ( value )
170
- this . binaryPath = value ;
172
+ this . binaryPath = this . sanitizePath ( value ) ;
171
173
break ;
172
174
173
175
default :
@@ -253,6 +255,11 @@ function Local(){
253
255
return args ;
254
256
} ;
255
257
258
+ this . sanitizePath = function ( rawPath ) {
259
+ var doubleQuoteIfRequired = this . windows && ! rawPath . match ( / " [ ^ " ] + " / ) ? '"' : '' ;
260
+ return doubleQuoteIfRequired + rawPath + doubleQuoteIfRequired ;
261
+ }
262
+
256
263
this . killAllProcesses = function ( callback ) {
257
264
psTree ( this . pid , ( err , children ) => {
258
265
var childPids = children . map ( val => val . PID ) ;
0 commit comments