diff --git a/procenv.cpp b/procenv.cpp index 344dc5d..ee4fbe0 100644 --- a/procenv.cpp +++ b/procenv.cpp @@ -25,17 +25,24 @@ */ #include +#include #include "process.hpp" int main(int argc, char **argv) { if (argc != 2) { - printf("procenv \n"); + std::cout << "procenv " << "\n"; return 0; } - int proc_id = std::stoi(argv[1]); + int proc_id; + try { + proc_id = std::stoi(argv[1]); + } catch (std::exception& e) { + std::cout << "Illegal PID: " << argv[1] << "\n"; + return 0; + } std::vector env = ngs::ps::environ_from_proc_id(proc_id); for (std::size_t j = 0; j < env.size(); j++) { - std::cout << env[j] << "\n"; + std::cout << env[j] << "\n"; } return 0; }