🐛 subprocess::terminate return correct value

This commit is contained in:
ValKmjolnir 2024-06-13 01:00:18 +08:00
parent 40ca6c19bf
commit 9752b8823e
2 changed files with 14 additions and 10 deletions

View File

@ -158,7 +158,11 @@ var builtin_subprocess_terminate(context* ctx, gc* ngc) {
auto pi = &static_cast<subprocess_descriptor*>(obj.ghost().pointer)->pi;
WaitForSingleObject(pi->hProcess, 0);
TerminateProcess(pi->hProcess, 0);
TerminateProcess(pi->hProcess, -1);
DWORD res;
GetExitCodeProcess(pi->hProcess, &res);
CloseHandle(pi->hProcess);
CloseHandle(pi->hThread);
#else
@ -171,9 +175,11 @@ var builtin_subprocess_terminate(context* ctx, gc* ngc) {
if (result==0) {
kill(pid, SIGTERM);
}
auto res = WIFEXITED(status)? WEXITSTATUS(status):-1;
#endif
return nil;
return var::num(res);
}
nasal_builtin_table subprocess_native[] = {

View File

@ -70,7 +70,7 @@ if (size(argv)==2) {
var modified_time = io.fstat(filename).st_mtime;
println(os_time(), info_hd(), "\e[1mwatching ", filename, " ..\e[0m");
while(1) {
unix.sleep(5);
unix.sleep(1);
if (!io.exists(filename)) {
println(
os_time(),
@ -91,7 +91,6 @@ while(1) {
foreach(var i; args) {
cmd ~= " " ~ i;
}
cmd ~= " 2>&1";
println(
os_time(),
info_hd(),
@ -100,12 +99,11 @@ while(1) {
"\"\e[0m"
);
var subproc = subprocess.popen(cmd);
var stdout_info = subprocess.read(subproc);
var ret = subprocess.pclose(subproc);
if (size(stdout_info)>0) {
println(stdout_info);
}
var subproc = subprocess.create(["nasal", filename]~args);
unix.sleep(2);
var ret = subprocess.terminate(subproc);
println(
os_time(),
ret!=0? err_hd():info_hd(),