diff --git a/.gitignore b/.gitignore index c872901..4515463 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ .vs -x64 -x86 +.vscode +build *.h *.rc *.aps *.sln *.vcxproj -*.vcxproj.* \ No newline at end of file +*.vcxproj.* +*.obj \ No newline at end of file diff --git a/CMD_to_Bash.cpp b/CMD_to_Bash.cpp index 9a3e40e..c01d5cb 100644 --- a/CMD_to_Bash.cpp +++ b/CMD_to_Bash.cpp @@ -1,40 +1,33 @@ -#include -#include +#include +#include using namespace std; int main(int argc, char* argv[]) { - char drive[_MAX_DRIVE]; - char dir[_MAX_DIR]; - char fname[_MAX_FNAME]; - char ext[_MAX_EXT]; - _splitpath_s(argv[0], drive, sizeof(drive), dir, sizeof(dir), fname, sizeof(fname), ext, sizeof(ext)); + char drive[_MAX_DRIVE]; + char dir[_MAX_DIR]; + char fname[_MAX_FNAME]; + char ext[_MAX_EXT]; + _splitpath_s(argv[0], drive, _countof(drive), dir, _countof(dir), fname, _countof(fname), ext, _countof(ext)); - string ch = "bash.exe -c \"\\\"\""; - ch += fname; - int count = 1; - for (count; count < argc; ++count) { - ch += " "; - ch += argv[count]; - } - ch += "\\\"\"\""; + string ch = "bash.exe -c \"\\\"\""; + ch += fname; + for (int i = 1; i < argc; ++i) { + ch += " "; + ch += argv[i]; + } + ch += "\\\"\"\""; - DWORD dwExitCode; - wstring widstr; - widstr = wstring(ch.begin(), ch.end()); - LPWSTR sConLin = (LPWSTR)widstr.c_str(); + DWORD dwExitCode; + STARTUPINFO si = { sizeof(si) }; + PROCESS_INFORMATION pi; - STARTUPINFO si; - PROCESS_INFORMATION pi; - memset(&si, 0, sizeof(si)); - memset(&pi, 0, sizeof(pi)); + CreateProcess(NULL, (LPSTR)ch.c_str(), NULL, NULL, true, 0, NULL, NULL, &si, &pi); - CreateProcess(NULL, sConLin, NULL, NULL, true, 0, NULL, NULL, &si, &pi); - - CloseHandle(pi.hThread); - WaitForSingleObject(pi.hProcess, INFINITE); - GetExitCodeProcess(pi.hProcess, &dwExitCode); - CloseHandle(pi.hProcess); - - return dwExitCode; + CloseHandle(pi.hThread); + WaitForSingleObject(pi.hProcess, INFINITE); + GetExitCodeProcess(pi.hProcess, &dwExitCode); + CloseHandle(pi.hProcess); + + return dwExitCode; }