Skip to content

Commit 92f1721

Browse files
committed
Fixes, Exit and Die added
1 parent af377c5 commit 92f1721

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

exec.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import (
44
"bytes"
55
"fmt"
66
"log"
7+
"os"
78
"os/exec"
89
)
910

1011
// Exec - Start a command on system
12+
// Original : https://www.php.net/manual/tr/function.exec.php
13+
// exec() executes the given command.
1114
func Exec(of string) {
1215
var out bytes.Buffer
1316
cmd := exec.Command(of)
@@ -18,7 +21,9 @@ func Exec(of string) {
1821
}
1922
}
2023

21-
// ShellExec - Start a command on system
24+
// ShellExec - Execute command via shell and return the complete output as a string
25+
// Original : https://www.php.net/manual/en/function.shell-exec.php
26+
// This function is identical to the backtick operator.
2227
func ShellExec(of string) {
2328
var out bytes.Buffer
2429
cmd := exec.Command(of)
@@ -29,3 +34,17 @@ func ShellExec(of string) {
2934
}
3035
fmt.Printf("%q\n", out.String())
3136
}
37+
38+
// Exit - Output a message and terminate the current script
39+
// Original : https://www.php.net/manual/en/function.exit.php
40+
// Terminates execution of the script. Shutdown functions and object destructors will always be executed even if exit is called.
41+
func Exit(of int) {
42+
os.Exit(of)
43+
}
44+
45+
// Die - Equivalent to exit
46+
// Original : https://www.php.net/manual/en/function.die.php
47+
// This language construct is equivalent to exit().
48+
func Die(of int) {
49+
os.Exit(of)
50+
}

time.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,28 @@ import "time"
88

99
// Time - Similar function of time() in PHP.
1010
// Original : https://www.php.net/manual/en/function.time.php
11+
// Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
1112
func Time() int64 {
1213
return time.Now().Unix()
1314
}
1415

1516
// Now - Similar function of time() in PHP.
1617
// Original : https://www.php.net/manual/en/function.time.php
18+
// Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
1719
func Now() int64 {
1820
return time.Now().Unix()
1921
}
2022

2123
// Sleep - Delay in seconds
2224
// Original : https://www.php.net/manual/en/function.sleep.php
25+
// Delays the program execution for the given number of seconds.
2326
func Sleep(t int64) {
2427
time.Sleep(time.Duration(t) * time.Second)
2528
}
2629

2730
// USleep - Delay in microseconds
2831
// Original : https://www.php.net/manual/en/function.usleep.php
32+
// Delays program execution for the given number of microseconds.
2933
func USleep(t int64) {
3034
time.Sleep(time.Duration(t) * time.Microsecond)
3135
}

0 commit comments

Comments
 (0)