简体   繁体   English

从go lang程序启动终端窗口?

[英]Launch terminal window from go lang program?

I want to have a functionality in which i will create an go program running on linux system. 我想拥有一个功能,可以创建在Linux系统上运行的go程序。 When that program is running it will download a zip folder from server & extract it to user HOME directory. 该程序运行时,它将从服务器下载一个zip folder并将其解zip folder到用户HOME目录。 That extracted folder will have a shell script file eg. 该提取的文件夹将具有一个shell脚本文件,例如。 Update.sh . Update.sh Now i want once that file is extracted i want to open the terminal & run the shell script automatically which resides inside extracted folder. 现在,我想一旦解压缩该文件,就想打开终端并自动运行驻留在解压缩文件夹内的shell脚本。 Kindly gudie me can i do that ? 亲爱的我,我能做到吗?

Have you looked at the Go standard library? 您是否看过Go标准库? Your best bet is os/exec . 最好的选择是os / exec I don't know how feasible it would be to open another terminal and launch the script in it , but you can pipe the output of the command launched by os/exec to the stdout of the terminal in which the go program was launched. 我不知道打开另一个终端并在其中启动脚本是多么可行,但是您可以将os / exec启动的命令的输出通过管道传递到启动go程序的终端的stdout。

From your question, it sounds like the go program downloading and running the script is already being run by the user on the local machine. 从您的问题来看,听起来好像本地用户已经在运行go程序下载和运行脚本。 If this is not the case, then the above will not work. 如果不是这种情况,则以上操作将无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM