1 Star 1 Fork 1

up-zero/gotool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
exec_test.go 905 Bytes
一键复制 编辑 原始数据 按行查看 历史
GetcharZp 提交于 2023-08-14 18:26 +08:00 . feat 带通知的运行命令
package gotool
import (
"testing"
)
func TestExecShell(t *testing.T) {
t.Log(ExecShell("ls -al"))
t.Log(ExecShell("dir"))
}
func TestExecCommand(t *testing.T) {
t.Log(ExecCommand("ls", "-al"))
t.Log(ExecCommand("go", "version"))
}
func TestExecCommandWithNotify(t *testing.T) {
ch := make(chan string)
finish := make(chan struct{})
go func() {
for {
select {
case data := <-ch:
t.Log("data => ", data)
case <-finish:
return
}
}
}()
if err := ExecCommandWithNotify(ch, "go", "version"); err != nil {
t.Fatal(err)
}
finish <- struct{}{}
}
func TestExecShellWithNotify(t *testing.T) {
ch := make(chan string)
finish := make(chan struct{})
go func() {
for {
select {
case data := <-ch:
t.Log("data => ", data)
case <-finish:
return
}
}
}()
if err := ExecShellWithNotify(ch, "dir"); err != nil {
t.Fatal(err)
}
finish <- struct{}{}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/up-zero/gotool.git
git@gitee.com:up-zero/gotool.git
up-zero
gotool
gotool
main

搜索帮助