-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleProxy.cpp
More file actions
44 lines (41 loc) · 1.8 KB
/
Copy pathConsoleProxy.cpp
File metadata and controls
44 lines (41 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// ConsoleProxy.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "Console.h"
#define MAX_BUFFER_SIZE 4096
int main()
{
Console cmdConsole;
if (cmdConsole.CreateChildProcess())
{
DWORD dw;
string msg;
CHAR buff[MAX_BUFFER_SIZE];
while (TRUE)
{
getline(cin, msg);
if (msg == "exit" || msg == "EXIT")
{
break;
}
//printf("%s\r\n", msg.c_str());
if ( !cmdConsole.Write(msg.c_str(), msg.length()) )
{
printf("%s:[%d] write failed. \r\n", __FILE__, __LINE__);
dw = GetLastError();
printf("GetLastError-->%u\n", GetLastError());
ExitProcess(dw);
}
if ( !cmdConsole.Read(buff, sizeof(buff)) )
{
printf("%s:[%d] write failed. \r\n", __FILE__, __LINE__);
dw = GetLastError();
printf("GetLastError-->%u\n", dw);
ExitProcess(dw);
}
printf("%s", buff);
}
}
system("pause");
return 0;
}