Home > Backend Development > Golang > Go exec.Command: Why 'no such file or directory'?

Go exec.Command: Why 'no such file or directory'?

Mary-Kate Olsen
Release: 2024-12-31 05:42:17
Original
907 people have browsed it

Go exec.Command: Why

Go: fork/exec . no such file or directory

Problem:

When using Go 1.10.2 on macOS, you encounter the "no such file or directory" error with the following code:

cmd := exec.Command(c)
Copy after login

where c is a string containing the command to be executed.

Answer:

The error indicates that the specified command doesn't exist or cannot be found in the current directory. To resolve this, ensure that the executable file for the command is present in the current working directory or is available in the path environment variable.

Additionally, the signature of exec.Command has been updated since you may have encountered this error. The current signature is:

func Command(name string, args ...string) *Cmd
Copy after login

where name is the name of the program and args are the arguments to be passed to the program.

To resolve the issue, try modifying your code as follows:

cmd := exec.Command("./goreplay", "--input-file", gor_name, "--input-file-loop", "--output-http", ras_ip)
Copy after login

This should ensure that the "no such file or directory" error is resolved.

The above is the detailed content of Go exec.Command: Why 'no such file or directory'?. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template