Skip to content

Commit 1d274d3

Browse files
authored
Merge pull request #115 from citricity/issue_113_open_dbclient_app
Issue #113: Copilot code review fixes
2 parents e87a9ec + c12ccbe commit 1d274d3

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/Traits/ExecTrait.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Traits;
44

55
use App\Exceptions\ExecFailed;
6+
use App\Helpers\OS;
67

78
trait ExecTrait {
89
protected bool $verbose = false;
@@ -64,7 +65,19 @@ protected function execDetached(string $cmd): void {
6465
}
6566
// Execute command in background to detach from PHP process
6667
// This allows GUI applications to get proper focus
67-
exec($cmd . ' &');
68+
69+
// This is made OS-aware to work correctly on both Unix-like systems and Windows.
70+
if (OS::isWindows()) {
71+
// On Windows, use "start" to launch a detached process.
72+
// The empty title ("") is required to avoid treating the first argument as the window title.
73+
$detachedCmd = 'start "" ' . $cmd;
74+
} else {
75+
// On Unix-like systems.
76+
$detachedCmd = "($cmd) &";
77+
}
78+
$output = [];
79+
$returnVar = 0;
80+
exec($detachedCmd, $output, $returnVar);
6881
}
6982

7083
protected function execPassthru(string $cmd, ?string $errorMsg = null): void {

0 commit comments

Comments
 (0)