Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Traits/ExecTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Traits;

use App\Exceptions\ExecFailed;
use App\Helpers\OS;

trait ExecTrait {
protected bool $verbose = false;
Expand Down Expand Up @@ -64,7 +65,19 @@ protected function execDetached(string $cmd): void {
}
// Execute command in background to detach from PHP process
// This allows GUI applications to get proper focus
exec($cmd . ' &');

// This is made OS-aware to work correctly on both Unix-like systems and Windows.
if (OS::isWindows()) {
// On Windows, use "start" to launch a detached process.
// The empty title ("") is required to avoid treating the first argument as the window title.
$detachedCmd = 'start "" ' . $cmd;
} else {
// On Unix-like systems.
$detachedCmd = "($cmd) &";
}
$output = [];
$returnVar = 0;
exec($detachedCmd, $output, $returnVar);
}

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