Skip to content

Commit 18a8a2b

Browse files
committed
Added windows functions to allow this to work on windows systems.
1 parent fc19fd9 commit 18a8a2b

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

src/GO/Job.php

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,19 @@ public function onlyOne($tempDir = null, callable $whenOverlapping = null)
263263
$tempDir = $this->tempDir;
264264
}
265265

266-
$this->lockFile = implode('/', [
267-
trim($tempDir),
268-
trim($this->id) . '.lock',
269-
]);
266+
if(file_exists('/dev/null')){
267+
//linux systems
268+
$this->lockFile = implode('/', [
269+
trim($tempDir),
270+
trim($this->id) . '.lock',
271+
]);
272+
}else{
273+
//windows systems need back slashes for file paths
274+
$this->lockFile = implode('\\', [
275+
trim(str_replace('/', '\\', $tempDir)),
276+
trim($this->id) . '.lock',
277+
]);
278+
}
270279

271280
if ($whenOverlapping) {
272281
$this->whenOverlapping = $whenOverlapping;
@@ -303,8 +312,15 @@ public function compile()
303312

304313
// Add the boilerplate to redirect the output to file/s
305314
if (count($this->outputTo) > 0) {
306-
$compiled .= ' | tee ';
307-
$compiled .= $this->outputMode === 'a' ? '-a ' : '';
315+
if(file_exists('/dev/null')){
316+
//linux systems
317+
$compiled .= ' | tee ';
318+
$compiled .= $this->outputMode === 'a' ? '-a ' : '';
319+
}else{
320+
//windows systems
321+
$compiled .= ' ';
322+
$compiled .= $this->outputMode === 'a' ? '>> ' : '> ';
323+
}
308324
foreach ($this->outputTo as $file) {
309325
$compiled .= $file . ' ';
310326
}
@@ -314,14 +330,26 @@ public function compile()
314330

315331
// Add boilerplate to remove lockfile after execution
316332
if ($this->lockFile) {
317-
$compiled .= '; rm ' . $this->lockFile;
333+
if(file_exists('/dev/null')){
334+
//linux systems
335+
$compiled .= '; rm ' . $this->lockFile;
336+
}else{
337+
//windows systems
338+
$compiled .= ' & del ' . $this->lockFile;
339+
}
318340
}
319341

320342
// Add boilerplate to run in background
321343
if ($this->canRunInBackground()) {
322344
// Parentheses are need execute the chain of commands in a subshell
323345
// that can then run in background
324-
$compiled = '(' . $compiled . ') > /dev/null 2>&1 &';
346+
if(file_exists('/dev/null')){
347+
//linux systems
348+
$compiled = '(' . $compiled . ') > /dev/null 2>&1 &';
349+
}else{
350+
//windows systems
351+
$compiled = '(' . $compiled . ') > NUL 2>&1';
352+
}
325353
}
326354

327355
return trim($compiled);

0 commit comments

Comments
 (0)