-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.go
63 lines (50 loc) · 2.91 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
Package Process provides a method to spawn child processes,
like os/exec package, but with one huge difference: on Windows
you have the capabilty of sending an Interrupt signal, that is
you can simulate a CTRL+C event to the child process, which
can then decide whether to handle it or not.
The underlying structure used to spawn and manage the process is
the exec.Cmd: for managing input, output and lifecycle of the process,
its highly recommended to use the functions provided by the package
The package also gives for Windows users some usefull functions
to recreate the behaviour via the various functions from the kernel32.dll
# Behaviour
By default, each child process is spawned in a new console/tty. This is required
for Windows to work so it's also the default behaviour in Linux for a consistent
implementation.
When starting a process, these are the options you can provide ...
For the stdin argument:
+ if you provide nil, the process will listen on the standard input provided by the new
environment, and no data can be sent through the pipe
+ if you provide process.DevNull(), the pipe will be created and usable, the child
will not use the standard input of the new console and will only receive data through
the pipe by the parent
+ for any other value, the pipe will be created and usable, and any data inside the
io.Reader provided will be passed through the pipe. This means that if you pass
os.Stdin, you can send data from the parent via the methods of the pipe and via
your console natively
For the stdout and stderr argument:
+ if you provide nil:
+ on Windows, the child will use the standard output / error of the new console,
you can't capture any data
+ on Unix-like systems, the child will write to the /dev/null device and you can't
capture any data
+ if you provide process.DevNull(), you will be able to access any data sent by the child,
but only through the process methods (no real standard output / error)
+ for any other value, any data will be captured and written to the io.Writer provided.
This means that if you pass os.Stdout/Stderr, you will also have the output sent to the parent console
# OS Compatibility
The package is obviously compatible with all operating systems,
but there are some differences:
> Non Windows OSes (Linux, Mac OS, etc)
Considering its natively supported to send signals between processes,
there is full support without any external program
> Windows
By default, in windows, the process is spawned in a different console (so has
different stdin, out and err from the parent) and is hidden, but this behaviour
can be reverted with the method Process.ShowWindow() by calling it before the start
This process might still fail, the reasons are still not known. For example, if the child
process you want to stop is created by the "go run" command, this will not work
*/
package process