-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.cpp
55 lines (46 loc) · 1.52 KB
/
runner.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <string>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <array>
int main();
int main()
{
std::string command("ssh -Y [email protected] '/home/pi/Documents/github/2427_radio/build/Chip_ID' 2>&1");
std::array<char, 128> buffer;
std::string result;
std::cout << "Opening remote reading pipe" << std::endl;
FILE* pipe = popen(command.c_str(), "r");
if (!pipe)
{
std::cerr << "Couldn't start command." << std::endl;
return 0;
}
while (fgets(buffer.data(), 128, pipe) != NULL) {
std::cout << "Reading..." << buffer.data();
result += buffer.data();
}
auto returnCode = pclose(pipe);
std::cout << result << std::endl;
bool isFound = result.find("43447");
if (isFound) std::cout << "The remote chip ID is correct" << std::endl;
std::cout << returnCode << std::endl;
std::string command1("'/home/pi/Documents/github/2427_radio/build/Chip_ID' 2>&1");
std::cout << "Opening local reading pipe" << std::endl;
pipe = popen(command1.c_str(), "r");
if (!pipe)
{
std::cerr << "Couldn't start command." << std::endl;
return 0;
}
while (fgets(buffer.data(), 128, pipe) != NULL) {
std::cout << "Reading..." << buffer.data();
result += buffer.data();
}
returnCode = pclose(pipe);
std::cout << result << std::endl;
isFound = result.find("43447");
if (isFound) std::cout << "The local chip ID is correct" << std::endl;
std::cout << returnCode << std::endl;
return 0;
}