Last active
August 25, 2019 07:31
-
-
Save suzuki-shunsuke/5553aaeb5a932e1bc0a74f3b485b0a9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment