1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os.exec: on unix return error, when the command was not found, instead of os.Result

This commit is contained in:
Delyan Angelov 2020-08-05 06:26:56 +03:00
parent c261408f54
commit ab7936f514
2 changed files with 10 additions and 8 deletions

View File

@ -148,9 +148,9 @@ pub fn exec(cmd string) ?Result {
soutput := res.str()
// res.free()
exit_code := vpclose(f)
// if exit_code != 0 {
// return error(res)
// }
if exit_code == 127 {
return error_with_code(soutput, 127)
}
return Result{
exit_code: exit_code
output: soutput

View File

@ -241,13 +241,15 @@ pub fn exec(cmd string) ?Result {
create_pipe_ok := C.CreatePipe(voidptr(&child_stdout_read),
voidptr(&child_stdout_write), voidptr(&sa), 0)
if !create_pipe_ok {
error_msg := get_error_msg(int(C.GetLastError()))
return error('exec failed (CreatePipe): $error_msg')
error_num := int(C.GetLastError())
error_msg := get_error_msg(error_num)
return error_with_code('exec failed (CreatePipe): $error_msg', error_num)
}
set_handle_info_ok := C.SetHandleInformation(child_stdout_read, C.HANDLE_FLAG_INHERIT, 0)
if !set_handle_info_ok {
error_msg := get_error_msg(int(C.GetLastError()))
panic('exec failed (SetHandleInformation): $error_msg')
error_num := int(C.GetLastError())
error_msg := get_error_msg(error_num)
return error_with_code('exec failed (SetHandleInformation): $error_msg', error_num)
}
proc_info := ProcessInformation{}
@ -267,7 +269,7 @@ pub fn exec(cmd string) ?Result {
if !create_process_ok {
error_num := int(C.GetLastError())
error_msg := get_error_msg(error_num)
return error('exec failed (CreateProcess) with code $error_num: $error_msg cmd: $cmd')
return error_with_code('exec failed (CreateProcess) with code $error_num: $error_msg cmd: $cmd', error_num)
}
C.CloseHandle(child_stdin)
C.CloseHandle(child_stdout_write)