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")
}
rcmd("goblin", "ls", "-r", "100", "src") && println("it works also")

View file

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