-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
33 lines (32 loc) · 997 Bytes
/
main.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
#include <iostream>
#include <string>
int main(int argc, char* argv[]) {
if (argc < 2) {
std::cout << "Missing file path" << std::endl;
return 1;
}
try {
std::string filePath = argv[1];
char buffer[256];
std::string wslCommand = "C:\\Windows\\System32\\wsl.exe bash -c \"$(wslpath '" + filePath + "')";
for (int i = 2; i < argc; i++){
std::string arg = argv[i];
wslCommand += " " + arg;
}
wslCommand += "\"";
FILE* wslProcess = _popen(wslCommand.c_str(), "r");
if (!wslProcess) {
std::cerr << "Error running WSL." << std::endl;
return 1;
}
while (fgets(buffer, sizeof(buffer), wslProcess)) {
std::cout << buffer;
}
std::cout << std::endl;
_pclose(wslProcess);
return 0;
} catch (const std::exception& e) {
std::cerr << "Exception: " << e.what() << std::endl;
return 1;
}
}