donglaoping9702 2017-02-28 05:02
浏览 415
已采纳

在Golang中使用Exec时如何隐藏命令提示符窗口?

say i have the following code, using syscall to hide command line window

process := exec.Command(name, args...)
process.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
err := process.Start()
if err != nil {
    log.Print(err)
}

but when i compiled it and tried to run it in Windows, command line window showed up again

what can i do to prevent command line window from appearing?

PS i already know how to compile golang source into a Windows GUI executable using go build -ldflags -H=windowsgui, but doing so only ensures the program itself doesn't bring up a command line window, Exec will show those windows anyway

  • 写回答

2条回答 默认 最新

  • duanmie9682 2018-01-21 10:44
    关注

    There is a better solution, which can run exec.Command() without spawn a visible window, ( ͡° ͜ʖ ͡°).

    Here is my code:

    Firstly import "syscall"

    cmd_path := "C:\\Windows\\system32\\cmd.exe"
    cmd_instance := exec.Command(cmd_path, "/c", "notepad")
    cmd_instance.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
    cmd_output, err := cmd_instance.Output()
    

    Origin: https://www.reddit.com/r/golang/comments/2c1g3x/build_golang_app_reverse_shell_to_run_in_windows/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!