We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
79
syscall
exec
1 parent 3dc094f commit a5c9989Copy full SHA for a5c9989
execingprocesses/main.go
@@ -1,6 +1,29 @@
1
package execingprocesses
2
3
-// Similarly to spawning a subprocess
+import (
4
+ "os"
5
+ "os/exec"
6
+ "syscall"
7
+)
8
+
9
+// Similarly to spawning a subprocess, exec
10
+// can replace the go process with another one
11
+// As always, taking user input into exec directly
12
+// is a serious security flaw and should be used with caution.
13
func Run() {
14
+ listFilesAndDirectories()
15
+}
16
17
+func listFilesAndDirectories() {
18
+ executable, err := exec.LookPath("ls")
19
+ if err != nil {
20
+ // POSIX only here again.
21
+ panic(err)
22
+ }
23
+ args := []string{"ls", "-a", "-l", "-h"}
24
+ env := os.Environ()
25
+ if err := syscall.Exec(executable, args, env); err != nil {
26
27
28
29
}
0 commit comments