Skip to content

Instantly share code, notes, and snippets.

@suzuki-shunsuke
Last active August 25, 2019 07:31

Revisions

  1. suzuki-shunsuke revised this gist Aug 25, 2019. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion exec_run.go
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ func main() {
    cmd := exec.Command("sh", "-c", "ls | fzf")
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    // it works as expected.
    // it works as expected.
    if err := cmd.Run(); err != nil {
    fmt.Println(err)
    }
    2 changes: 1 addition & 1 deletion timeout_run_context.go
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ func main() {
    KillAfter: 5 * time.Second,
    // Foreground: true,
    }
    // it doesn't work as expected.
    // it doesn't work as expected.
    exitStatus, err := tio.RunContext(context.Background())
    fmt.Println(exitStatus, err)
    }
  2. suzuki-shunsuke created this gist Aug 25, 2019.
    17 changes: 17 additions & 0 deletions exec_run.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    package main

    import (
    "fmt"
    "os"
    "os/exec"
    )

    func main() {
    cmd := exec.Command("sh", "-c", "ls | fzf")
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    // it works as expected.
    if err := cmd.Run(); err != nil {
    fmt.Println(err)
    }
    }
    26 changes: 26 additions & 0 deletions timeout_run_context.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    package main

    import (
    "context"
    "fmt"
    "os"
    "os/exec"
    "time"

    "github.com/Songmu/timeout"
    )

    func main() {
    cmd := exec.Command("sh", "-c", "ls | fzf")
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    tio := &timeout.Timeout{
    Cmd: cmd,
    Duration: 10 * time.Second,
    KillAfter: 5 * time.Second,
    // Foreground: true,
    }
    // it doesn't work as expected.
    exitStatus, err := tio.RunContext(context.Background())
    fmt.Println(exitStatus, err)
    }