CreateProcess("cmd.exe", "/k echo hello"
2013-04-29 14:39
190 查看
#include <AFX.H>//#include <Windows.H> #include <WINBASE.H> #include <stdio.H> int main(int argc,char** argv,char** env) { SECURITY_ATTRIBUTES sa; HANDLE hRead,hWrite; sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; if (!CreatePipe(&hRead,&hWrite,&sa,0)) { printf("Error On CreatePipe()\n"); return 1; } PROCESS_INFORMATION pi; STARTUPINFO si; si.cb = sizeof(STARTUPINFO); GetStartupInfo(&si); si.hStdError = hWrite; si.hStdOutput = hWrite; si.wShowWindow = SW_HIDE; si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; //if (!CreateProcess("C:\\WINDOWS\\system32\\cmd.exe", "/k echo hello", if (!CreateProcess("cmd.exe", "/k echo hello", NULL, NULL, TRUE, NULL, NULL, NULL, &si, &pi)) { printf("Error on CreateProcess():%ld\n",::GetLastError()); return 1; } CloseHandle(hWrite); const int BufferLength = 1024; CString showedMsg = ""; char buffer[BufferLength + 1] = {0}; DWORD bytesRead; while (ReadFile(hRead,buffer,BufferLength,&bytesRead,NULL)) { showedMsg+=buffer; //showedMsg.Append(buffer); // Sleep(200); } // if (showedMsg.Find("find Bugs") > 0) { // printf("Error \n"); // return 1; // } printf("%s \n",(LPCTSTR)showedMsg); return 0; }
相关文章推荐
- cmd.exe /c shutdown -r -t 60 -c "
- Failed executing 'cmd.exe /X /C ""C:\Program Files\Java\jdk1.6.0_38\jre\..\bin\jarsigner.exe"
- OpenCv编译错误-"cmd.exe" exited with code 1
- VS2008 C++编译中 提示”生成"cmd.exe"时出错 “
- VC2005中 提示”生成"cmd.exe"时出错 “
- VC2005中提示"生成cmd.exe时出错"的解决方法
- CustomBuild:拒绝访问。 error MSB6006: "cmd.exe" exited with code 1.
- 关于"生成cmd.exe"的解决方法
- Visual Studio 2005调试程序时提示"生成“cmd.exe”时出错".
- error "cmd.exe" exited with code 1
- 解决VS2008中 生成"cmd.exe"时出错
- Visual Studio 2005调试程序时老是提示"生成“cmd.exe”时出错".
- zendframework搭建为什么cmd窗口是这样的,"php.exe"' 不是内部或外部命令,也不是可运行的程序
- VC2005中 提示”生成"cmd.exe"时出错 “
- CustomBuild:拒绝访问。 error MSB6006: "cmd.exe" exited with code 1.
- 安装Visual Studio 6的"Error Lauching acmboot.exe"问题解决方法
- Blackberry version "hello world", which use a socket to send msg to a server
- VS2005下error PRJ0003 : Error spawning 'cmd.exe'的解决方法
- php的扩展和嵌入--c扩展开发demo! print "helloworld"
- Quartz "Hello World"