[DEV] add external exec component
This commit is contained in:
parent
14d615358f
commit
139fb3b758
30
etk-core/system.cpp
Normal file
30
etk-core/system.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#include <etk/Exception.hpp>
|
||||
#include <etk/system.hpp>
|
||||
#include <stdio.h>
|
||||
|
||||
etk::String etk::exec(const etk::String& _cmd) {
|
||||
FILE* pipe = popen(_cmd.c_str(), "r");
|
||||
if (!pipe) {
|
||||
ETK_THROW_EXCEPTION(etk::exception::RuntimeError("popen() failed!"));
|
||||
return "";
|
||||
}
|
||||
etk::String out;
|
||||
try {
|
||||
char buffer[128];
|
||||
while (fgets(buffer, 128, pipe) != NULL) {
|
||||
out += buffer;
|
||||
}
|
||||
} catch (...) {
|
||||
pclose(pipe);
|
||||
ETK_THROW_EXCEPTION(etk::exception::RuntimeError("Broken pipe"));
|
||||
}
|
||||
pclose(pipe);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
14
etk-core/system.hpp
Normal file
14
etk-core/system.hpp
Normal file
@ -0,0 +1,14 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.hpp>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace etk {
|
||||
etk::String exec(const etk::String& _cmd);
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ def configure(target, my_module):
|
||||
'etk-core/Allocator.cpp',
|
||||
'etk-core/typeInfo.cpp',
|
||||
'etk-core/Exception.cpp',
|
||||
'etk-core/system.cpp',
|
||||
])
|
||||
|
||||
my_module.add_header_file([
|
||||
@ -58,7 +59,8 @@ def configure(target, my_module):
|
||||
'etk-core/Function.hpp',
|
||||
'etk-core/NullPtr.hpp',
|
||||
'etk-core/typeInfo.hpp',
|
||||
'etk-core/Exception.hpp'
|
||||
'etk-core/Exception.hpp',
|
||||
'etk-core/system.hpp',
|
||||
], 'etk')
|
||||
|
||||
# build in C++ mode
|
||||
|
Loading…
Reference in New Issue
Block a user