File tree 1 file changed +11
-4
lines changed
1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -50,11 +50,18 @@ namespace matplot {
50
50
iequals (str, " no" );
51
51
}
52
52
53
+ struct pipe_deleter {
54
+ int operator ()(FILE* pipe) const {
55
+ if (int status = PCLOSE (pipe ); status != -1 )
56
+ return status;
57
+ throw std::system_error{errno, std::system_category (), " pclose" };
58
+ }
59
+ };
60
+
53
61
std::string run_and_get_output (const std::string &cmd) {
54
- std::unique_ptr<FILE, int (*)(FILE *)> pipe (POPEN (cmd.c_str (), " r" ),
55
- PCLOSE);
62
+ std::unique_ptr<FILE, pipe_deleter> pipe (POPEN (cmd.c_str (), " r" ));
56
63
if (!pipe ) {
57
- throw std::runtime_error ( " popen() failed! " ) ;
64
+ throw std::system_error{errno, std::system_category (), cmd} ;
58
65
}
59
66
std::array<char , 128 > buffer{};
60
67
std::string result;
@@ -363,7 +370,7 @@ namespace matplot {
363
370
std::string fileread (const std::string &filename) {
364
371
std::ifstream t (filename);
365
372
if (!t) {
366
- throw std::runtime_error ( " Cannot open the file " + filename);
373
+ throw std::system_error (errno, std::system_category (), filename);
367
374
}
368
375
std::string str ((std::istreambuf_iterator<char >(t)),
369
376
std::istreambuf_iterator<char >());
You can’t perform that action at this time.
0 commit comments