Skip to content

Commit cfeb641

Browse files
Compute the correct exit status and return
1 parent 51bbc8e commit cfeb641

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/bin/lpython.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ int main(int argc, char *argv[])
16491649
err = system(("js " + outfile +".js").c_str());
16501650
} else {
16511651
if (compiler_options.platform == LFortran::Platform::Windows) {
1652-
err = system(outfile.c_str());
1652+
return system(outfile.c_str());
16531653
} else {
16541654
err = system(("./" + outfile).c_str());
16551655
}
@@ -1658,7 +1658,9 @@ int main(int argc, char *argv[])
16581658
if (0 < err && err < 256) {
16591659
return err;
16601660
} else {
1661-
return 1;
1661+
// https://stackoverflow.com/a/27117435/15913193
1662+
// https://linux.die.net/man/3/system
1663+
return LFortran::get_exit_status(err);
16621664
}
16631665
}
16641666
}

src/lpython/utils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,8 @@ bool path_exists(std::string path) {
103103
}
104104
}
105105

106+
int32_t get_exit_status(int32_t err) {
107+
return (((err) >> 8) & 0x000000ff);
108+
}
109+
106110
}

src/lpython/utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ std::string get_runtime_library_header_dir();
1212
bool is_directory(std::string path);
1313
bool path_exists(std::string path);
1414

15+
int32_t get_exit_status(int32_t err);
16+
1517
} // LFortran
1618

1719
#endif // LFORTRAN_UTILS_H

0 commit comments

Comments
 (0)