printf("Usage: runnerw.exe <app> <args>\n");
printf("where <app> is console application and <args> it's arguments.\n");
printf("\n");
- printf("Runner invokes console application as a process with inherited input and output streams.\n");
- printf("Input stream is scanned for presence of 2 char 255(IAC) and 243(BRK) sequence and generates Ctrl-Break event in that case.\n");
- printf("Also in case of all type of event(Ctrl-C, Close, Shutdown etc) Ctrl-Break event is generated.\n");
+ printf(
+ "Runner invokes console application as a process with inherited input and output streams.\n");
+ printf(
+ "Input stream is scanned for presence of 2 char 255(IAC) and 243(BRK) sequence and generates Ctrl-Break event in that case.\n");
+ printf(
+ "Also in case of all type of event(Ctrl-C, Close, Shutdown etc) Ctrl-Break event is generated.\n");
exit(0);
}
BOOL is_iac = FALSE;
-char IAC = 'a';
-char BRK = 'b';
+char IAC = 255;
+char BRK = 243;
BOOL Scan(char buf[], int count) {
- for (int i = 0; i<count; i++) {
+ for (int i = 0; i < count; i++) {
if (is_iac) {
if (buf[i] == BRK) {
CtrlBreak();
return FALSE;
}
-BOOL CtrlHandler( DWORD fdwCtrlType )
-{
- switch( fdwCtrlType )
- {
- case CTRL_C_EVENT:
- case CTRL_CLOSE_EVENT:
- case CTRL_LOGOFF_EVENT:
- case CTRL_SHUTDOWN_EVENT:
- CtrlBreak();
- return( TRUE );
- case CTRL_BREAK_EVENT:
- return FALSE;
- default:
- return FALSE;
- }
+BOOL CtrlHandler(DWORD fdwCtrlType) {
+ switch (fdwCtrlType) {
+ case CTRL_C_EVENT:
+ case CTRL_CLOSE_EVENT:
+ case CTRL_LOGOFF_EVENT:
+ case CTRL_SHUTDOWN_EVENT:
+ CtrlBreak();
+ return (TRUE);
+ case CTRL_BREAK_EVENT:
+ return FALSE;
+ default:
+ return FALSE;
+ }
}
int main(int argc, char * argv[]) {
GetStartupInfo(&si);
- si.dwFlags = STARTF_USESTDHANDLES ;
+ si.dwFlags = STARTF_USESTDHANDLES;
si.wShowWindow = SW_HIDE;
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
char* c_args = new char[args.size() + 1];
strcpy(c_args, args.c_str());
- SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE);
+ SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
- if (!CreateProcess(c_app, // Application name
- c_args, // Application arguments
- NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE , NULL, NULL, &si, &pi)) {
+ if (!CreateProcess(c_app, // Application name
+ c_args, // Application arguments
+ NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &si, &pi)) {
ErrorMessage("CreateProcess");
CloseHandle(newstdin);
CloseHandle(write_stdin);
unsigned long b_write;
unsigned long avail;
- char buf[1];
+ char buf[1];
memset(buf, 0, sizeof(buf));
for (;;) {
if (exit != STILL_ACTIVE)
break;
- char c;
- std::cin >> c;
-// char c = fgetc();
- buf[0] = c;
- Scan(buf, 1);
- WriteFile(write_stdin, buf, 1, &b_write, NULL);
+ char c;
+ std::cin >> c;
+ buf[0] = c;
+ Scan(buf, 1);
+ WriteFile(write_stdin, buf, 1, &b_write, NULL);
}
CloseHandle(pi.hThread);