-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.go
36 lines (28 loc) · 1.01 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"fmt"
"log"
"os"
"github.com/vladimirvivien/gexe"
)
// This example shows how to execute OS commands concurrently and wait for the result.
func main() {
fmt.Println("Downloading 3 books concurrently from Gutenberg")
// The following launches each command concurrently to download long text from Gutenberg.
// The download should be faster than if ran sequentially.
result := gexe.RunConcur(
"wget -O /tmp/thenegro.txt https://www.gutenberg.org/cache/epub/15359/pg15359.txt",
"wget -O /tmp/fleece.txt https://www.gutenberg.org/cache/epub/15265/pg15265.txt",
"wget -O /tmp/conversation.txt https://www.gutenberg.org/cache/epub/31254/pg31254.txt",
)
// inspect result or check for errors.
if len(result.ErrProcs()) > 0 {
log.Println("One or more commands failed")
}
for _, path := range []string{"/tmp/thenegro.txt", "/tmp/fleece.txt", "/tmp/conversation.txt"} {
if _, err := os.Stat(path); err == nil {
fmt.Printf("file %s downloaded OK\n", path)
os.RemoveAll(path)
}
}
}