add tests

This commit is contained in:
Timofey Turenko
2017-05-17 18:16:06 +03:00
committed by Markus Mäkelä
parent dbfd631fed
commit 8c6ca38a8a
594 changed files with 48376 additions and 0 deletions

View File

@ -0,0 +1,44 @@
#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "execute_cmd.h"
using namespace std;
int execute_cmd(char * cmd, char ** res)
{
char * result;
FILE *output = popen(cmd, "r");
if (output == NULL)
{
printf("Error opening ssh %s\n", strerror(errno));
return -1;
}
char buffer[10240];
size_t rsize = sizeof(buffer);
result = (char*)calloc(rsize, sizeof(char));
while (fgets(buffer, sizeof(buffer), output))
{
result = (char*)realloc(result, sizeof(buffer) + rsize);
rsize += sizeof(buffer);
strcat(result, buffer);
}
* res = result;
int return_code = pclose(output);
if (WIFEXITED(return_code))
{
return WEXITSTATUS(return_code);
}
else
{
return -1;
}
}