main.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #include "win32.hpp"
  15. #include <stdio.h>
  16. int main(int argc, char** argv)
  17. {
  18. STARTUPINFO si={sizeof si, 0, NULL};
  19. PROCESS_INFORMATION pi;
  20. char* cmd=GetCommandLine();
  21. while (isspace(*cmd)) cmd++;
  22. if (*cmd=='"') {
  23. cmd++;
  24. while (*cmd && *cmd != '"')
  25. cmd++;
  26. if (*cmd)
  27. cmd++;
  28. } else {
  29. while (!isspace(*cmd)) cmd++;
  30. }
  31. while (isspace(*cmd)) cmd++;
  32. if(!::CreateProcess(NULL, cmd, NULL, NULL, FALSE, CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi))
  33. {
  34. win32::SystemError e("CreateProcess");
  35. fprintf(stderr,e.GetMessage());
  36. return -1;
  37. }
  38. CloseHandle(pi.hProcess);
  39. CloseHandle(pi.hThread);
  40. return 0;
  41. }