GoのTorにHUP信号を送信しようとしています。
command := exec.Command("pidof tor | xargs kill -HUP")
command.Dir = "/bin"
if cmdOut, err := command.CombinedOutput(); err != nil {
log.Panic("There was an error running HUP ", string(cmdOut), err)
panic(err)
}
私はこれの多数のバージョンを試してみました(引数あり/なし、ディレクトリあり/なし...)、常に同じエラーが返されます:
2017/06/27 13:36:31 There was an error running HUP exec: "pidof tor | xargs kill -HUP": executable file not found in $PATH
panic: There was an error running HUP exec: "pidof tor | xargs kill -HUP": executable file not found in $PATH
goroutine 1 [running]:
panic(0x639ac0, 0xc42000d260)
/usr/local/go/src/runtime/panic.go:500 +0x1a1
log.Panic(0xc420049f08, 0x3, 0x3)
/usr/local/go/src/log/log.go:320 +0xc9
main.main()
コンソールからコマンドを実行すると、完全に機能します。
root@c8927c4a456e:/go/src/github.com/project# pidof tor | xargs kill -HUP
Jun 27 13:40:07.000 [notice] Received reload signal (hup). Reloading config and resetting internal state.
Jun 27 13:40:07.000 [notice] Read configuration file "/etc/tor/torrc".
これが私の$ PATHです
root@c8927c4a456e:/go/src/github.com/project# echo $PATH
/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
私は以前にgitコマンドを使用してこれを実行し、シームレスに動作していました。何か不足していますか?
ドキュメントによれば、最初に渡される引数はexec.Command
実行可能ファイルの名前です-それだけです。シェルでは解釈されません。フォークしたい実行可能ファイルの名前です。引数を渡す必要がある場合は、追加のパラメータとしてにCommand
渡すか、後で返されたオブジェクトに渡すことができます。
あなたの場合、2つのコマンドを使用して、1つのstdoutを別のstdoutにパイプしています。純粋なGoでこれを行う(一方のStdoutリーダーを他方のStdinライターにパイプする)か、シェルを使用して行うことができます。後者の場合、実行可能ファイルはsh
またはbash
、引数はになります["-c", "pidof tor | xargs kill -HUP"]
。例えば:
cmd := exec.Command("bash", "-c", "pidof tor | xargs kill -HUP")
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加