From ef6f93be43f9a4bbc30a3741185c6e894e029d02 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 16 Apr 2024 11:12:56 +0200 Subject: [PATCH] Initial commit --- .gitignore | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 3 ++ run-sync.go | 56 ++++++++++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 .gitignore create mode 100644 go.mod create mode 100644 run-sync.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b66a8f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,110 @@ +# Created by .ignore support plugin (hsz.mobi) +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/ + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +### Go template +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +vendor/ + +### macOS template +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Linux template +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +*.bak +*.bak.* +*.log +.env +.cache.docker/ +.cache/ +cache.docker/ +/data +coverage.* +bin/server* +.run/ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a4bb4fb --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.webz.asia/experiments/run-sync + +go 1.21.3 diff --git a/run-sync.go b/run-sync.go new file mode 100644 index 0000000..2e8db5e --- /dev/null +++ b/run-sync.go @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 - now, Alex + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Alex + * @copyright Copyright (c) 2024 - now, Alex + * @since 16.04.2024 + * + */ + +package run_sync + +import ( + "bytes" + "log" + "os/exec" + "time" +) + +func RunProcessSync(command string, args ...string) (out *bytes.Buffer, err error) { + cmd := exec.Command(command, args...) + // Output buffer + out = &bytes.Buffer{} + cmd.Stdout = out + cmd.Stderr = out + + err = cmd.Start() + if err != nil { + return + } + + err = cmd.Wait() + if err != nil { + return + } + + time.Sleep(5 * time.Second) + + output := []string{"[runProcessSync]", command} + output = append(output, args...) + output = append(output, "Output:", out.String()) + log.Println(output) + + return +}