summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-02-22 06:53:24 -0600
committerJeff Carr <[email protected]>2025-02-22 06:53:24 -0600
commite621f228badee0f27d04055cfe4381264bdf2abf (patch)
treec0a4b5c180a866305e81a8f92e92b2de4f61a3e0
parent590ce71782e7374b3d82eeed33c39dfd706b0b95 (diff)
-rw-r--r--exec.go56
-rw-r--r--exec_linux.go62
2 files changed, 62 insertions, 56 deletions
diff --git a/exec.go b/exec.go
index 16f4967..3d9a195 100644
--- a/exec.go
+++ b/exec.go
@@ -2,10 +2,8 @@ package shell
import (
"errors"
- "fmt"
"os"
"os/exec"
- "syscall"
"go.wit.com/log"
)
@@ -71,57 +69,3 @@ func PathExecVerbose(path string, args []string) error {
// log.Info("ExecCheck() nil")
return nil
}
-
-func SudoRaw(c []string) {
- args := []string{"-S"}
- args = append(args, c...)
- cmd := exec.Command("sudo", args...)
-
- // Assign the current process's standard input, output, and error
- cmd.Stderr = os.Stderr
- cmd.Stdout = os.Stdout
- cmd.Stdin = os.Stdin
-
- // Ensure the process has a terminal session
- cmd.SysProcAttr = &syscall.SysProcAttr{
- Setsid: true, // Start a new session
- }
-
- err := cmd.Run()
- if err != nil {
- fmt.Println("Command execution failed:", err)
- }
-}
-
-func Sudo(c []string) error {
- args := []string{"-S"}
- // args := []string{}
- args = append(args, c...)
- cmd := exec.Command("sudo", args...)
-
- // Open the terminal device directly to preserve input/output control
- tty, err := os.OpenFile("/dev/tty", os.O_RDWR, 0)
- if err != nil {
- fmt.Println("Failed to open /dev/tty:", err)
- return err
- }
- defer tty.Close()
-
- // Assign the TTY explicitly
- cmd.Stdin = tty
- cmd.Stdout = tty
- cmd.Stderr = tty
-
- // Ensure the new process gets its own session
- cmd.SysProcAttr = &syscall.SysProcAttr{
- Setsid: true, // Start a new session
- }
-
- // Run the command
- if err := cmd.Run(); err != nil {
- fmt.Println("Command execution failed:", err)
- }
-
- fmt.Println("\nProcess finished. TTY restored.")
- return nil
-}
diff --git a/exec_linux.go b/exec_linux.go
new file mode 100644
index 0000000..233a848
--- /dev/null
+++ b/exec_linux.go
@@ -0,0 +1,62 @@
+package shell
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+ "syscall"
+)
+
+func SudoRaw(c []string) {
+ args := []string{"-S"}
+ args = append(args, c...)
+ cmd := exec.Command("sudo", args...)
+
+ // Assign the current process's standard input, output, and error
+ cmd.Stderr = os.Stderr
+ cmd.Stdout = os.Stdout
+ cmd.Stdin = os.Stdin
+
+ // Ensure the process has a terminal session
+ cmd.SysProcAttr = &syscall.SysProcAttr{
+ Setsid: true, // Start a new session
+ }
+
+ err := cmd.Run()
+ if err != nil {
+ fmt.Println("Command execution failed:", err)
+ }
+}
+
+func Sudo(c []string) error {
+ args := []string{"-S"}
+ // args := []string{}
+ args = append(args, c...)
+ cmd := exec.Command("sudo", args...)
+
+ // Open the terminal device directly to preserve input/output control
+ tty, err := os.OpenFile("/dev/tty", os.O_RDWR, 0)
+ if err != nil {
+ fmt.Println("Failed to open /dev/tty:", err)
+ return err
+ }
+ defer tty.Close()
+
+ // Assign the TTY explicitly
+ cmd.Stdin = tty
+ cmd.Stdout = tty
+ cmd.Stderr = tty
+
+ // Ensure the new process gets its own session
+ cmd.SysProcAttr = &syscall.SysProcAttr{
+ Setsid: true, // Start a new session
+ }
+
+ // Run the command
+ if err := cmd.Run(); err != nil {
+ fmt.Println("Command execution failed:", err)
+ }
+
+ fmt.Println("\nProcess finished. TTY restored.")
+ return nil
+}