When utilizing exec.Command in Golang, encountering the enigmatic "exit status 1" error leaves one scratching their head for specifics. This article aims to illuminate this error's cause and provide a solution for more detailed diagnostics.
Consider the following code:
cmd := exec.Command("find", "/", "-maxdepth", "1", "-exec", "wc", "-c", "{}", "\\") var out bytes.Buffer cmd.Stdout = &out err := cmd.Run()
Executing this code results in the uninformative "exit status 1" error. To remedy this, leverage the Stderr property of the Command object:
var stderr bytes.Buffer cmd.Stderr = &stderr
Upon executing, the error message will become apparent:
exit status 1: find: -exec: no terminating ";" or "+"
Now, equipped with this detailed error, you can address the issue accordingly.
Note: It's worth considering that some commands may redirect error messages to stdout rather than stderr. Additionally, certain commands may print error messages to stderr but still return a zero error code (leading to a nil err in your code). Therefore, it may be necessary to adjust the given solution to accommodate the specific commands you're using.
위 내용은 Go의 exec.Command가 "종료 상태 1"을 반환하는 이유는 무엇이며 추가 정보를 어떻게 얻을 수 있습니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!