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
f3c35198
Commit
f3c35198
authored
Jun 02, 2011
by
Brad Fitzpatrick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exec: missing docs, errors
R=rsc CC=golang-dev
https://golang.org/cl/4550111
parent
e59aa8ea
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
1 deletion
+26
-1
exec.go
src/pkg/exec/exec.go
+26
-1
No files found.
src/pkg/exec/exec.go
View file @
f3c35198
...
@@ -63,6 +63,7 @@ type Cmd struct {
...
@@ -63,6 +63,7 @@ type Cmd struct {
err
os
.
Error
// last error (from LookPath, stdin, stdout, stderr)
err
os
.
Error
// last error (from LookPath, stdin, stdout, stderr)
process
*
os
.
Process
process
*
os
.
Process
finished
bool
// when Wait was called
childFiles
[]
*
os
.
File
childFiles
[]
*
os
.
File
closeAfterStart
[]
*
os
.
File
closeAfterStart
[]
*
os
.
File
closeAfterWait
[]
*
os
.
File
closeAfterWait
[]
*
os
.
File
...
@@ -182,7 +183,7 @@ func (c *Cmd) writerDescriptor(w io.Writer) (f *os.File, err os.Error) {
...
@@ -182,7 +183,7 @@ func (c *Cmd) writerDescriptor(w io.Writer) (f *os.File, err os.Error) {
return
pw
,
nil
return
pw
,
nil
}
}
// Run
run
s the specified command and waits for it to complete.
// Run
start
s the specified command and waits for it to complete.
//
//
// The returned error is nil if the command runs, has no problems
// The returned error is nil if the command runs, has no problems
// copying stdin, stdout, and stderr, and exits with a zero exit
// copying stdin, stdout, and stderr, and exits with a zero exit
...
@@ -198,6 +199,7 @@ func (c *Cmd) Run() os.Error {
...
@@ -198,6 +199,7 @@ func (c *Cmd) Run() os.Error {
return
c
.
Wait
()
return
c
.
Wait
()
}
}
// Start starts the specified command but does not wait for it to complete.
func
(
c
*
Cmd
)
Start
()
os
.
Error
{
func
(
c
*
Cmd
)
Start
()
os
.
Error
{
if
c
.
err
!=
nil
{
if
c
.
err
!=
nil
{
return
c
.
err
return
c
.
err
...
@@ -239,10 +241,24 @@ func (c *Cmd) Start() os.Error {
...
@@ -239,10 +241,24 @@ func (c *Cmd) Start() os.Error {
return
nil
return
nil
}
}
// Wait waits for the command to exit.
// It must have been started by Start.
//
// The returned error is nil if the command runs, has no problems
// copying stdin, stdout, and stderr, and exits with a zero exit
// status.
//
// If the command fails to run or doesn't complete successfully, the
// error is of type *os.Waitmsg. Other error types may be
// returned for I/O problems.
func
(
c
*
Cmd
)
Wait
()
os
.
Error
{
func
(
c
*
Cmd
)
Wait
()
os
.
Error
{
if
c
.
process
==
nil
{
if
c
.
process
==
nil
{
return
os
.
NewError
(
"exec: not started"
)
return
os
.
NewError
(
"exec: not started"
)
}
}
if
c
.
finished
{
return
os
.
NewError
(
"exec: Wait was already called"
)
}
c
.
finished
=
true
msg
,
err
:=
c
.
process
.
Wait
(
0
)
msg
,
err
:=
c
.
process
.
Wait
(
0
)
var
copyError
os
.
Error
var
copyError
os
.
Error
...
@@ -267,6 +283,9 @@ func (c *Cmd) Wait() os.Error {
...
@@ -267,6 +283,9 @@ func (c *Cmd) Wait() os.Error {
// Output runs the command and returns its standard output.
// Output runs the command and returns its standard output.
func
(
c
*
Cmd
)
Output
()
([]
byte
,
os
.
Error
)
{
func
(
c
*
Cmd
)
Output
()
([]
byte
,
os
.
Error
)
{
if
c
.
Stdout
!=
nil
{
return
nil
,
os
.
NewError
(
"exec: Stdout already set"
)
}
var
b
bytes
.
Buffer
var
b
bytes
.
Buffer
c
.
Stdout
=
&
b
c
.
Stdout
=
&
b
err
:=
c
.
Run
()
err
:=
c
.
Run
()
...
@@ -276,6 +295,12 @@ func (c *Cmd) Output() ([]byte, os.Error) {
...
@@ -276,6 +295,12 @@ func (c *Cmd) Output() ([]byte, os.Error) {
// CombinedOutput runs the command and returns its combined standard
// CombinedOutput runs the command and returns its combined standard
// output and standard error.
// output and standard error.
func
(
c
*
Cmd
)
CombinedOutput
()
([]
byte
,
os
.
Error
)
{
func
(
c
*
Cmd
)
CombinedOutput
()
([]
byte
,
os
.
Error
)
{
if
c
.
Stdout
!=
nil
{
return
nil
,
os
.
NewError
(
"exec: Stdout already set"
)
}
if
c
.
Stderr
!=
nil
{
return
nil
,
os
.
NewError
(
"exec: Stderr already set"
)
}
var
b
bytes
.
Buffer
var
b
bytes
.
Buffer
c
.
Stdout
=
&
b
c
.
Stdout
=
&
b
c
.
Stderr
=
&
b
c
.
Stderr
=
&
b
...
...
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