diff --git a/checkin_notes b/checkin_notes index d479bc58d7..3e0677035e 100644 --- a/checkin_notes +++ b/checkin_notes @@ -8055,3 +8055,9 @@ David 3 Nov 2011 acct_mgr.cpp app.cpp cpu_sched.cpp + +David 3 Nov 2011 + - wrapper: handle Windows .bat files as main programs + + samples/wrapper/ + wrapper.cpp diff --git a/samples/wrapper/wrapper.cpp b/samples/wrapper/wrapper.cpp index 020020012a..64aee1a7fc 100644 --- a/samples/wrapper/wrapper.cpp +++ b/samples/wrapper/wrapper.cpp @@ -442,18 +442,38 @@ int TASK::run(int argct, char** argvt) { set_up_env_vars(&env_vars, nvars); } - if (!CreateProcess( - app_path, - (LPSTR)command.c_str(), - NULL, - NULL, - TRUE, // bInheritHandles - CREATE_NO_WINDOW|IDLE_PRIORITY_CLASS, - (LPVOID) env_vars, - exec_dir.empty()?NULL:exec_dir.c_str(), - &startup_info, - &process_info - )) { + BOOL success; + if (ends_with((string)app_path, ".bat")) { + char cmd[1024]; + sprintf(cmd, "cmd.exe /c %s", command.c_str()); + success = CreateProcess( + "cmd.exe", + app_path, + (LPSTR)cmd, + NULL, + NULL, + TRUE, // bInheritHandles + CREATE_NO_WINDOW|IDLE_PRIORITY_CLASS, + (LPVOID) env_vars, + exec_dir.empty()?NULL:exec_dir.c_str(), + &startup_info, + &process_info + ); + } else { + success = CreateProcess( + app_path, + (LPSTR)command.c_str(), + NULL, + NULL, + TRUE, // bInheritHandles + CREATE_NO_WINDOW|IDLE_PRIORITY_CLASS, + (LPVOID) env_vars, + exec_dir.empty()?NULL:exec_dir.c_str(), + &startup_info, + &process_info + ); + } + if (!success) { char error_msg[1024]; windows_error_string(error_msg, sizeof(error_msg)); fprintf(stderr, "can't run app: %s\n", error_msg);