mirror of
https://github.com/minio/minio.git
synced 2024-12-25 14:45:54 -05:00
Switching execpipe output to io.Reader
This commit is contained in:
parent
d1fe8beff5
commit
14dec50fef
@ -3,6 +3,7 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -10,7 +11,7 @@ import (
|
|||||||
// Each command's standard output is connected to the standard input of the next command
|
// Each command's standard output is connected to the standard input of the next command
|
||||||
// and the output of the final command is returned
|
// and the output of the final command is returned
|
||||||
|
|
||||||
func ExecPipe(cmds ...*exec.Cmd) (pipeLineOutput []byte, pipeLineError error) {
|
func ExecPipe(cmds ...*exec.Cmd) (pipeLineOutput io.Reader, pipeLineError error) {
|
||||||
// Require at least one command
|
// Require at least one command
|
||||||
if len(cmds) < 1 {
|
if len(cmds) < 1 {
|
||||||
return nil, errors.New("Invalid argument")
|
return nil, errors.New("Invalid argument")
|
||||||
@ -30,17 +31,17 @@ func ExecPipe(cmds ...*exec.Cmd) (pipeLineOutput []byte, pipeLineError error) {
|
|||||||
// Start each command
|
// Start each command
|
||||||
for _, cmd := range cmds {
|
for _, cmd := range cmds {
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
return output.Bytes(), err
|
return &output, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We should Wait() for each command to complete
|
// We should Wait() for each command to complete
|
||||||
for _, cmd := range cmds {
|
for _, cmd := range cmds {
|
||||||
if err := cmd.Wait(); err != nil {
|
if err := cmd.Wait(); err != nil {
|
||||||
return output.Bytes(), err
|
return &output, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the output
|
// Return the output
|
||||||
return output.Bytes(), nil
|
return &output, nil
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,11 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "gopkg.in/check.v1"
|
"io/ioutil"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MySuite struct{}
|
type MySuite struct{}
|
||||||
@ -29,6 +31,8 @@ func (s *MySuite) TestPiping(c *C) {
|
|||||||
// Run
|
// Run
|
||||||
output, err := ExecPipe(ls, sort)
|
output, err := ExecPipe(ls, sort)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(len(output), Not(Equals), 0)
|
outputBytes, err := ioutil.ReadAll(output)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Assert(len(outputBytes), Not(Equals), 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user