fix popen errors
This commit is contained in:
parent
b5ed40e2f2
commit
09eac7708c
|
@ -417,8 +417,8 @@ static int f_popen(lua_State *L) {
|
||||||
CloseHandle(pi.hProcess);
|
CloseHandle(pi.hProcess);
|
||||||
CloseHandle(pi.hThread);
|
CloseHandle(pi.hThread);
|
||||||
#else
|
#else
|
||||||
FILE* pipe = popen(cmd, "rb");
|
FILE* pipe = popen(cmd, "r");
|
||||||
if (pipe == NULL) { luaL_error(L, "Failed to start process"); }
|
if (pipe == NULL) { luaL_error(L, "Failed to start process: %d", errno); }
|
||||||
|
|
||||||
size_t read;
|
size_t read;
|
||||||
while(!feof(pipe)) {
|
while(!feof(pipe)) {
|
||||||
|
@ -426,7 +426,8 @@ static int f_popen(lua_State *L) {
|
||||||
read = fread(b, sizeof(char), LUAL_BUFFERSIZE, pipe);
|
read = fread(b, sizeof(char), LUAL_BUFFERSIZE, pipe);
|
||||||
luaL_addsize(&stdoutBuf, read);
|
luaL_addsize(&stdoutBuf, read);
|
||||||
}
|
}
|
||||||
exitCode = WEXITSTATUS(pclose(pipe));
|
int status = pclose(pipe);
|
||||||
|
if (WIFEXITED(status)) { exitCode = WEXITSTATUS(status); }
|
||||||
#endif
|
#endif
|
||||||
luaL_pushresult(&stdoutBuf);
|
luaL_pushresult(&stdoutBuf);
|
||||||
lua_pushnumber(L, exitCode);
|
lua_pushnumber(L, exitCode);
|
||||||
|
|
Loading…
Reference in New Issue