Documentation ¶
Index ¶
- Variables
- func Execute(ctx context.Context, name string, args ...string) ([]byte, error)
- func ExecuteToString(ctx context.Context, name string, args ...string) (string, error)
- func NewCommand(ctx context.Context, name string, args []string, options ...CmdOption) *exec.Cmd
- type CmdOption
- type CmdOptions
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Execute ¶
Execute 执行命令(会阻塞直到命令结束)
!!!: (1) exec.Cmd结构体执行时,会处理路径中的空格(e.g. java可执行文件的绝对路径、-Djava.ext.dirs=的路径...) (2) 假如自行处理命令行中的路径,反而会导致: 命令执行失败
func ExecuteToString ¶
ExecuteToString 执行命令(会阻塞直到命令结束)
func NewCommand ¶
NewCommand
PS: (1) Cmd.Start(): 不会阻塞; (2) Cmd.Run(): 会阻塞.
@param ctx (1) 如果命令在ctx超时之前没有完成,CommandContext将会杀死该进程;
(2) !!!: 存在部分杀不死的情况,比如yozo的logon.exe,ctx超时了进程还是卡死在那(通过go代码执行会卡死在那,且无法通过ctx结束;但直接在command里面执行就没问题).
@param args 可以为nil
Types ¶
type CmdOption ¶
type CmdOption func(opts *CmdOptions)
type CmdOptions ¶
type CmdOptions struct { // Setpgid sets the process group ID of the child to Pgid, // or, if Pgid == 0, to the new child's process ID. Setpgid bool // Pdeathsig, if non-zero, is a signal that the kernel will send to // the child process when the creating thread dies. Note that the signal // is sent on thread termination, which may happen before process termination. // There are more details at https://go.dev/issue/27505. Pdeathsig syscall.Signal }
CmdOptions 参考: exec_linux.go
func (CmdOptions) NewCommand ¶
Click to show internal directories.
Click to hide internal directories.