Error: "fork/exec . no such file or directory" in Go with fork/exec
When running the following Go code, you may encounter the error "fork/exec . no such file or directory":
func loop1(gor_name string, ras_ip string) { // ... c := fmt.Sprintf("%s %s %s %s", "./goreplay --input-file ", gor_name, " --input-file-loop --output-http ", ras_ip) cmd := exec.Command(c) // ... }
This error occurs because the function exec.Command requires the program name as the first argument followed by its arguments. The code is currently specifying the entire command as a single string, leading to the error.
To resolve this issue, modify the code to use the correct function signature:
cmd := exec.Command("./goreplay", "--input-file", gor_name, "--input-file-loop", "--output-http", ras_ip)
In this updated code, the program name "goreplay" and its arguments are passed as separate parameters to exec.Command.
The above is the detailed content of Why Does My Go Code Return 'fork/exec . no such file or directory' When Using `exec.Command`?. For more information, please follow other related articles on the PHP Chinese website!