1#include <iostream>
2#include <windows.h>
3#include <fstream>
4
5using namespace std;
6int _tmain(int argc, _TCHAR* argv[])
7{
8 HANDLE hWrite,hRead;
9 SECURITY_ATTRIBUTES sa;
10 sa.bInheritHandle=true;
11 sa.nLength=sizeof(sa);
12 sa.lpSecurityDescriptor=NULL;
13
14 HANDLE input=CreateFile(L"in.txt",GENERIC_READ,NULL,&sa,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
15 HANDLE output=CreateFile(L"out.txt",GENERIC_WRITE|GENERIC_READ,NULL,&sa,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
16
17 //::CreatePipe(&hRead,&hWrite,&sa,0);
18 STARTUPINFO si;
19 ZeroMemory(&si,sizeof(si));
20 si.cb=sizeof(si);
21 ::GetStartupInfo(&si);
22 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
23 si.hStdError=0;
24 si.hStdInput=input;
25 si.hStdOutput=output;
26 si.wShowWindow=SW_HIDE;
27
28 PROCESS_INFORMATION pi;
29
30 CreateProcess(L"..\\Debug\\test.exe",0,0,0,true,0,0,0,&si,&pi);
31 //::CloseHandle(hWrite);
32 WaitForSingleObject(pi.hProcess,INFINITE);
33 CloseHandle(input);
34 CloseHandle(output);
35 //char mm[1000];
36 //memset(mm,0,sizeof(mm));
37 //DWORD d;
38 //ReadFile(hRead,mm,1000,&d,0);
39
40 //cout<<mm<<endl;
41
42 return 0;
43}
posted on 2009-03-11 13:15
小果子 阅读(237)
评论(0) 编辑 收藏 引用 所属分类:
Windows