How to Launch a Separate Command Window for a Golang Application on Windows?

DDD
Release: 2024-10-31 21:52:17
Original
680 people have browsed it

How to Launch a Separate Command Window for a Golang Application on Windows?

Launching a Separate Command Window with Golang on Windows

Question:

In a Go application utilizing the command window for user input and output, how do you launch an additional application instance with its own dedicated command window?

Initial Attempts:

The issue arose when attempts to use the "os/exec" package and execute the application with "cmd /c" failed to create a separate window. This led to the question of whether it was possible to launch a non-GUI application with its own window and accessible input/output.

Solution:

The breakthrough came with the realization that the "start" command could be used following "cmd /c". The updated code below successfully launches the application in a separate window:

<code class="go">cmd := exec.Command("cmd", "/C", "start", _path_to_executable_)
err := cmd.Start()</code>
Copy after login

The above is the detailed content of How to Launch a Separate Command Window for a Golang Application on Windows?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!