
質問内容
いくつかのコマンドを実行してみます(config.json内)
npm コマンドのみに出力が表示されます
スタックオーバーフローを初めて使用します
うまくできなかった場合はご容赦ください
期待される結果:
config.jsonにコマンドを書くと
正しい結果が出力されます
main.go
リーリー
構成.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | func main () {
file, _ := os.open( "config.json" )
byteres, _ := ioutil.readall(file)
var config config
json.unmarshal(byteres, &config)
defer file.close()
process := exec .command(config.startcommand)
stdout, _ := process.stdoutpipe()
processscanner := bufio.newscanner(stdout)
processscanner.split(bufio.scanlines)
process.start()
go func() {
for processscanner.scan() {
message := processscanner.text()
fmt.println(message)
}
}()
}
|
ログイン後にコピー
Solution
main 関数は、ゴルーチンの完了を待ちません。 sync.WaitGroup を使用して、ゴルーチンが完了するまで main
をブロックします。
以上がGolang コマンドを実行しようとすると出力がありませんの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。