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

在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 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格