Last active
November 10, 2018 02:01
-
-
Save aladram/4296ed85fc12980329372b5595af3d11 to your computer and use it in GitHub Desktop.
wsl.exe replacement for pre-1709 Windows builds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cstring> | |
| #include <iostream> | |
| #include <numeric> | |
| #include <string> | |
| extern "C" { | |
| #include <process.h> | |
| } | |
| // Path of bash.exe executable | |
| #define BASH_PATH "C:\\Windows\\System32\\bash.exe" | |
| /** | |
| * Concatenate args given in arguments | |
| * | |
| * @precondition: args_len >= 1 | |
| */ | |
| static auto join_args(char ** args, int args_len) | |
| { | |
| return std::accumulate<char**, std::string>( | |
| args + 1, | |
| args + args_len, | |
| std::string(args[0]), | |
| [](auto a, auto b) | |
| { | |
| a += ' '; | |
| a += b; | |
| return a; | |
| } | |
| ); | |
| } | |
| int main(int argc, char ** argv) | |
| { | |
| using namespace std::string_literals; | |
| if (argc < 3 || argv[1] != "run"s) | |
| { | |
| std::cerr << "Usage: " << argv[0] << " run <cmd>" << std::endl; | |
| return 1; | |
| } | |
| auto joined_args = join_args(argv + 2, argc - 2); | |
| auto ret = _spawnl(_P_WAIT, BASH_PATH, BASH_PATH, "-c", ("test; " + joined_args).c_str(), nullptr); | |
| if (ret == -1) | |
| { | |
| std::cerr << "An error occured during call to " << std::endl; | |
| return 1; | |
| } | |
| return ret; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment