Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
80d2eac1
Commit
80d2eac1
authored
Mar 01, 2013
by
Rémy Oudompheng
Committed by
Russ Cox
Mar 01, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/cgo: don't reimplement os/exec in util.go.
R=golang-dev, rsc CC=golang-dev
https://golang.org/cl/7450049
parent
e02168f6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
43 deletions
+10
-43
util.go
src/cmd/cgo/util.go
+10
-43
No files found.
src/cmd/cgo/util.go
View file @
80d2eac1
...
...
@@ -5,9 +5,9 @@
package
main
import
(
"bytes"
"fmt"
"go/token"
"io/ioutil"
"os"
"os/exec"
)
...
...
@@ -16,50 +16,17 @@ import (
// It returns the output to standard output and standard error.
// ok indicates whether the command exited successfully.
func
run
(
stdin
[]
byte
,
argv
[]
string
)
(
stdout
,
stderr
[]
byte
,
ok
bool
)
{
cmd
,
err
:=
exec
.
LookPath
(
argv
[
0
])
if
err
!=
nil
{
fatalf
(
"exec %s: %s"
,
argv
[
0
],
err
)
}
r0
,
w0
,
err
:=
os
.
Pipe
()
if
err
!=
nil
{
fatalf
(
"%s"
,
err
)
}
r1
,
w1
,
err
:=
os
.
Pipe
()
if
err
!=
nil
{
fatalf
(
"%s"
,
err
)
}
r2
,
w2
,
err
:=
os
.
Pipe
()
if
err
!=
nil
{
fatalf
(
"%s"
,
err
)
}
p
,
err
:=
os
.
StartProcess
(
cmd
,
argv
,
&
os
.
ProcAttr
{
Files
:
[]
*
os
.
File
{
r0
,
w1
,
w2
}})
if
err
!=
nil
{
fatalf
(
"%s"
,
err
)
}
r0
.
Close
()
w1
.
Close
()
w2
.
Close
()
c
:=
make
(
chan
bool
)
go
func
()
{
w0
.
Write
(
stdin
)
w0
.
Close
()
c
<-
true
}()
go
func
()
{
stdout
,
_
=
ioutil
.
ReadAll
(
r1
)
r1
.
Close
()
c
<-
true
}()
stderr
,
_
=
ioutil
.
ReadAll
(
r2
)
r2
.
Close
()
<-
c
<-
c
state
,
err
:=
p
.
Wait
()
if
err
!=
nil
{
p
:=
exec
.
Command
(
argv
[
0
],
argv
[
1
:
]
...
)
p
.
Stdin
=
bytes
.
NewReader
(
stdin
)
var
bout
,
berr
bytes
.
Buffer
p
.
Stdout
=
&
bout
p
.
Stderr
=
&
berr
err
:=
p
.
Run
()
if
_
,
ok
:=
err
.
(
*
exec
.
ExitError
);
err
!=
nil
&&
!
ok
{
fatalf
(
"%s"
,
err
)
}
ok
=
state
.
Success
()
ok
=
p
.
ProcessState
.
Success
()
stdout
,
stderr
=
bout
.
Bytes
(),
berr
.
Bytes
()
return
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment