Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a98c429f54 | ||
|
9f23666738 | ||
|
cd295a93b6 |
3
LICENSE
3
LICENSE
@ -69,5 +69,4 @@ http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
See the License for the specific language governin
|
50
README.md
50
README.md
@ -1,4 +1,50 @@
|
||||
# Library for executing bash commands with captured output.
|
||||
|
||||
# Library for executing bash commands with captured output
|
||||
|
||||
The output of the bash command is saved in a C++ string.
|
||||
|
||||
|
||||
The output of the bash command is saved in a C++ string.
|
||||
## Features
|
||||
|
||||
- Execute command send as string
|
||||
- Return string as command response
|
||||
- Thread safe
|
||||
- Throws an exception when cant pipe stream in execute command
|
||||
|
||||
## Installation
|
||||
|
||||
Just download the latest release and unzip it into your project. You can turn it on with:
|
||||
|
||||
```
|
||||
#include "exec/lib/exec.hpp"
|
||||
using namespace marcelb;
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```c++
|
||||
/**
|
||||
* Run bash command and store output
|
||||
*/
|
||||
string out = exec("ls -lha");
|
||||
|
||||
/**
|
||||
* Print response
|
||||
*/
|
||||
cout << out << endl;
|
||||
```
|
||||
## License
|
||||
|
||||
[APACHE 2.0](http://www.apache.org/licenses/LICENSE-2.0/)
|
||||
|
||||
|
||||
## Support & Feedback
|
||||
|
||||
For support and any feedback, contact the address: marcelb96@yahoo.com.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are always welcome!
|
||||
|
||||
Feel free to fork and start working with or without a later pull request. Or contact for suggest and request an option.
|
||||
|
||||
|
@ -6,11 +6,14 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace marcelb {
|
||||
|
||||
/**
|
||||
* Execute bash command
|
||||
*/
|
||||
string exec(const string& command);
|
||||
|
||||
string exec(const string command);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -1,6 +1,6 @@
|
||||
#include "../lib/exec.hpp"
|
||||
|
||||
string exec(const string command) {
|
||||
string marcelb::exec(const string& command) {
|
||||
FILE *fds;
|
||||
char cstr[200];
|
||||
fds = popen(command.c_str(), "r");
|
||||
|
@ -3,13 +3,12 @@
|
||||
#include "../lib/exec.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace marcelb;
|
||||
|
||||
int main() {
|
||||
|
||||
string out = exec("ls -lha");
|
||||
|
||||
cout << out << endl;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
BIN
test/test.o
BIN
test/test.o
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user