Skip to content

Commit e4b6e84

Browse files
authored
feat: shadow printing (#1)
1 parent d72a162 commit e4b6e84

39 files changed

Lines changed: 894 additions & 485 deletions

File tree

README.md

Lines changed: 225 additions & 289 deletions
Large diffs are not rendered by default.

creationflags_nonwindows.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//go:build !windows
2+
3+
package execx
4+
5+
const (
6+
// CreateNewProcessGroup starts the process in a new process group.
7+
CreateNewProcessGroup = 0x00000200
8+
// CreateNewConsole creates a new console for the process.
9+
CreateNewConsole = 0x00000010
10+
// CreateNoWindow prevents console windows from being created.
11+
CreateNoWindow = 0x08000000
12+
)

creationflags_windows.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//go:build windows
2+
3+
package execx
4+
5+
import "syscall"
6+
7+
const (
8+
// CreateNewProcessGroup starts the process in a new process group.
9+
CreateNewProcessGroup = syscall.CREATE_NEW_PROCESS_GROUP
10+
// CreateNewConsole creates a new console for the process.
11+
CreateNewConsole = syscall.CREATE_NEW_CONSOLE
12+
// CreateNoWindow prevents console windows from being created.
13+
CreateNoWindow = syscall.CREATE_NO_WINDOW
14+
)

examples/arg/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ func main() {
1212
// Arg appends arguments to the command.
1313

1414
// Example: add args
15-
cmd := execx.Command("go", "env").Arg("GOOS")
15+
cmd := execx.Command("printf").Arg("hello")
1616
out, _ := cmd.Output()
17-
fmt.Println(out != "")
18-
// #bool true
17+
fmt.Print(out)
18+
// hello
1919
}

examples/combinedoutput/main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ func main() {
1212
// CombinedOutput executes the command and returns stdout+stderr and any error.
1313

1414
// Example: combined output
15-
out, _ := execx.Command("go", "env", "GOOS").CombinedOutput()
16-
fmt.Println(out != "")
17-
// #bool true
15+
out, err := execx.Command("go", "env", "-badflag").CombinedOutput()
16+
fmt.Print(out)
17+
fmt.Println(err == nil)
18+
// flag provided but not defined: -badflag
19+
// usage: go env [-json] [-changed] [-u] [-w] [var ...]
20+
// Run 'go help env' for details.
21+
// false
1822
}

examples/command/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ func main() {
1212
// Command constructs a new command without executing it.
1313

1414
// Example: command
15-
cmd := execx.Command("go", "env", "GOOS")
15+
cmd := execx.Command("printf", "hello")
1616
out, _ := cmd.Output()
17-
fmt.Println(out != "")
18-
// #bool true
17+
fmt.Print(out)
18+
// hello
1919
}

examples/creationflags/main.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ import (
99
)
1010

1111
func main() {
12-
// CreationFlags sets Windows creation flags.
12+
// CreationFlags sets Windows process creation flags (for example, create a new process group).
1313

1414
// Example: creation flags
15-
fmt.Println(execx.Command("go", "env", "GOOS").CreationFlags(0) != nil)
16-
// #bool true
17-
// Example: creation flags
18-
fmt.Println(execx.Command("go", "env", "GOOS").CreationFlags(0) != nil)
19-
// #bool true
15+
out, _ := execx.Command("printf", "ok").CreationFlags(execx.CreateNewProcessGroup).Output()
16+
fmt.Print(out)
17+
// ok
2018
}

examples/gracefulshutdown/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func main() {
1616
// Example: graceful shutdown
1717
proc := execx.Command("sleep", "2").Start()
1818
_ = proc.GracefulShutdown(os.Interrupt, 100*time.Millisecond)
19-
res, err := proc.Wait()
20-
fmt.Println(err != nil || res.ExitCode != 0)
19+
res, _ := proc.Wait()
20+
fmt.Println(res.IsSignal(os.Interrupt))
2121
// #bool true
2222
}

examples/hidewindow/main.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ import (
99
)
1010

1111
func main() {
12-
// HideWindow controls window visibility and sets CREATE_NO_WINDOW for console apps.
12+
// HideWindow hides console windows and sets CREATE_NO_WINDOW for console apps.
1313

1414
// Example: hide window
15-
fmt.Println(execx.Command("go", "env", "GOOS").HideWindow(true) != nil)
16-
// #bool true
17-
// Example: hide window
18-
fmt.Println(execx.Command("go", "env", "GOOS").HideWindow(true) != nil)
19-
// #bool true
15+
out, _ := execx.Command("printf", "ok").HideWindow(true).Output()
16+
fmt.Print(out)
17+
// ok
2018
}

examples/interrupt/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func main() {
1414
// Example: interrupt
1515
proc := execx.Command("sleep", "2").Start()
1616
_ = proc.Interrupt()
17-
res, err := proc.Wait()
18-
fmt.Println(err != nil || res.ExitCode != 0)
19-
// #bool true
17+
res, _ := proc.Wait()
18+
fmt.Printf("%+v", res)
19+
// {Stdout: Stderr: ExitCode:-1 Err:<nil> Duration:75.987ms signal:interrupt}
2020
}

0 commit comments

Comments
 (0)