aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-12-17 08:51:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-12-17 08:51:35 +0200
commitc90760488f8a11886d2bb2baee4cc2714ac2fc83 (patch)
treea10d1e692192b1e76ce1e074553a6c1d6c09745a
parent0cb36399cc23f8efa83134cbca689b74478ee597 (diff)
Add support for printing canonical process exit status description
-rw-r--r--libbutl/process.cxx17
-rw-r--r--libbutl/process.mxx12
2 files changed, 29 insertions, 0 deletions
diff --git a/libbutl/process.cxx b/libbutl/process.cxx
index d5a35c0..f6c498e 100644
--- a/libbutl/process.cxx
+++ b/libbutl/process.cxx
@@ -104,6 +104,23 @@ using namespace butl::win32;
namespace butl
{
+ // process_exit
+ //
+ ostream&
+ operator<< (ostream& os, process_exit pe)
+ {
+ if (pe.normal ())
+ os << "exited with code " << static_cast<uint16_t> (pe.code ());
+ else
+ {
+ os << "terminated abnormally: " << pe.description ();
+ if (pe.core ())
+ os << " (core dumped)";
+ }
+
+ return os;
+ }
+
// process
//
static process_path
diff --git a/libbutl/process.mxx b/libbutl/process.mxx
index af6f995..27c13fa 100644
--- a/libbutl/process.mxx
+++ b/libbutl/process.mxx
@@ -200,6 +200,18 @@ LIBBUTL_MODEXPORT namespace butl
description () const;
};
+ // Print canonical exit status diagnostics:
+ //
+ // "terminated abnormally: <...> (core dumped)"
+ // "exited with code <...>"
+ //
+ // So you would normally do:
+ //
+ // cerr << "process " << args[0] << " " << *pr.exit << endl;
+ //
+ LIBBUTL_SYMEXPORT std::ostream&
+ operator<< (std::ostream&, process_exit);
+
class LIBBUTL_SYMEXPORT process
{
public: