-
Notifications
You must be signed in to change notification settings - Fork 8
/
exec.go
50 lines (45 loc) · 1.18 KB
/
exec.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
package phpfuncs
import (
"bytes"
"fmt"
"log"
"os"
"os/exec"
)
// Exec - Start a command on system
// Original : https://www.php.net/manual/tr/function.exec.php
// exec() executes the given command.
func Exec(of string) {
var out bytes.Buffer
cmd := exec.Command(of)
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
}
// ShellExec - Execute command via shell and return the complete output as a string
// Original : https://www.php.net/manual/en/function.shell-exec.php
// This function is identical to the backtick operator.
func ShellExec(of string) {
var out bytes.Buffer
cmd := exec.Command(of)
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%q\n", out.String())
}
// Exit - Output a message and terminate the current script
// Original : https://www.php.net/manual/en/function.exit.php
// Terminates execution of the script. Shutdown functions and object destructors will always be executed even if exit is called.
func Exit(of int) {
os.Exit(of)
}
// Die - Equivalent to exit
// Original : https://www.php.net/manual/en/function.die.php
// This language construct is equivalent to exit().
func Die(of int) {
os.Exit(of)
}