Basic idea for nohup started but needs more research.

master
Zed A. Shaw 1 week ago
parent 8457f3d60d
commit dbdd22c2ac
  1. 2
      nohup/.gitignore
  2. 3
      nohup/Makefile
  3. 7
      nohup/go.mod
  4. 4
      nohup/go.sum
  5. 45
      nohup/main.go

2
nohup/.gitignore vendored

@ -0,0 +1,2 @@
nohup
nohup.exe

@ -0,0 +1,3 @@
build:
go build .

@ -0,0 +1,7 @@
module lcthw.dev/go/go-coreutils/nohup
go 1.25.3
require github.com/mattn/go-isatty v0.0.20
require golang.org/x/sys v0.6.0 // indirect

@ -0,0 +1,4 @@
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

@ -0,0 +1,45 @@
package main
import (
"fmt"
"os"
"os/exec"
"github.com/mattn/go-isatty"
"flag"
"log"
"io"
)
func main() {
flag.Parse()
prog := flag.Args()[0]
// ignore SIGHUP
if isatty.IsTerminal(os.Stdout.Fd()) {
fmt.Println("Is Terminal")
} else if isatty.IsCygwinTerminal(os.Stdout.Fd()) {
fmt.Println("Is cygwin/msys2 terminal")
} else {
cmd := exec.Command(prog)
if cmd.Err != nil { log.Fatal(cmd.Err) }
in, err := cmd.StdinPipe()
if err != nil { log.Fatal(err) }
in.Close()
stdout, err := cmd.StdoutPipe()
if err != nil { log.Fatal(err) }
stderr, err := cmd.StderrPipe()
if err != nil { log.Fatal(err) }
output := io.MultiReader(stdout, stderr)
err = cmd.Start()
if err != nil { log.Fatal(err) }
_, err = io.Copy(os.Stdout, output)
if err != nil { log.Fatal(err) }
}
}
Loading…
Cancel
Save