From 7be6a335dfe0ee62c945e52b97563e788488e56f Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Tue, 31 Jan 2023 18:06:47 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Add=20`system=5Fquiet`=20helper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xcschemes/PHP Monitor DEV.xcscheme | 2 +- phpmon/Common/Core/Logger.swift | 6 +++--- phpmon/Common/Helpers/System.swift | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor DEV.xcscheme b/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor DEV.xcscheme index 403e4f6..db36ef9 100644 --- a/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor DEV.xcscheme +++ b/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor DEV.xcscheme @@ -91,7 +91,7 @@ + isEnabled = "NO"> /dev/null") - _ = system("rm ~/.config/phpmon/last_session.log 2> /dev/null") - _ = system("touch ~/.config/phpmon/last_session.log 2> /dev/null") + system_quiet("mkdir -p ~/.config/phpmon 2> /dev/null") + system_quiet("rm ~/.config/phpmon/last_session.log 2> /dev/null") + system_quiet("touch ~/.config/phpmon/last_session.log 2> /dev/null") self.logExists = FileSystem.fileExists(self.logFilePath) } } diff --git a/phpmon/Common/Helpers/System.swift b/phpmon/Common/Helpers/System.swift index 332bba2..e12e546 100644 --- a/phpmon/Common/Helpers/System.swift +++ b/phpmon/Common/Helpers/System.swift @@ -26,3 +26,21 @@ public func system(_ command: String) -> String { return output } + +/** + Run a simple blocking Shell command on the user's own system. + This variation does not return the output. + Avoid using this method in favor of the fakeable Shell class unless needed for express system operations. + */ +public func system_quiet(_ command: String) { + let task = Process() + task.launchPath = "/bin/sh" + task.arguments = ["-c", command] + + let pipe = Pipe() + task.standardOutput = pipe + task.launch() + + _ = pipe.fileHandleForReading.readDataToEndOfFile() + return +}