Simplpified anko rcmd piping functions.

This commit is contained in:
Andrey Parhomenko 2023-06-09 18:10:38 +03:00
parent 23c55cb466
commit 507953c348
2 changed files with 10 additions and 32 deletions

View file

@ -6,3 +6,5 @@ if v < 55 {
println("it fucking works") println("it fucking works")
} }
rcmd("goblin", "ls", "-r", "100", "src") && println("it works also")

View file

@ -106,46 +106,22 @@ func setupEnv() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
go func(){
obuf := make([]byte, 512) _, err = io.Copy(stdin, input)
go func() { if err != nil {
var ( panic(err)
err error
n int
)
for {
n, err = stdout.Read(obuf)
output.Write(obuf[:n])
if err == io.EOF {
break
} else if err != nil {
panic(err)
}
} }
stdout.Close()
}() }()
ibuf := make([]byte, 512)
go func() { go func() {
var ( _, err = io.Copy(output, stdout)
err error if err != nil {
n int panic(err)
)
for {
n, err = input.Read(ibuf)
stdin.Write(ibuf[:n])
if err == io.EOF {
break
} else if err != nil {
panic(err)
}
} }
stdin.Close()
}() }()
err = rcmd.Wait() err = rcmd.Wait()
if err != nil { if err != nil {
//fmt.Println(err) fmt.Println(err)
return false return false
} }