File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33namespace App \Traits ;
44
55use App \Exceptions \ExecFailed ;
6+ use App \Helpers \OS ;
67
78trait 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 {
You can’t perform that action at this time.
0 commit comments