如何得到CMD的返回信息??? 用CreateProcess执行一条CMD命令,怎么样能得到命令的返回信息呢?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在 MSDN 里查找这个标题 “Creating a Child Process with Redirected Input and Output”提供了一个例程 CreateProcess( ... );waitforsingleobject( ... );GetExitCodeProcess( ... ); int main(){ //char *a = getneedreplacestring( "public static void main(){ printf ( \"%s\\n\", \"hello, world!\" );}", "hello", "-HELLO-" ); //printf( "%s\n", a ); //delete []a; //a = NULL; STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); // Start the child process. if( !CreateProcess( NULL, // No module name (use command line). "d:\\bb.exe", // Command line. NULL, // Process handle not inheritable. NULL, // Thread handle not inheritable. FALSE, // Set handle inheritance to FALSE. 0, // No creation flags. NULL, // Use parent's environment block. NULL, // Use parent's starting directory. &si, // Pointer to STARTUPINFO structure. &pi ) // Pointer to PROCESS_INFORMATION structure. ) { printf( "CreateProcess failed.\n" ); return 1; } // Wait until child process exits. WaitForSingleObject( pi.hProcess, INFINITE ); unsigned long l; GetExitCodeProcess( pi.hProcess, &l ); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); printf( "exited with %d\n", l ); return 0; }aa.cmain(){ return 0;}bb.cmain(){ return 1;} dir > output.txtoutput.txt中就是DIR后显示的内容了.这样也许更简便. 怎么用ODBC把具有一定格式的BCP文件导入已存在的SQL表中? 从CListCtrl获取数据,在图片框按数据画点,画线 新手求助如何获取COMBO BOX选中值 请教:在COM中使用CDialog CString数据的拆分 大侠能否分享个程序 这样的程序会不会出现内存泄漏?? 关于VC中的字对齐 向大家请教一些关于netmeeting所用技术的问题 有关对话框的问题 对话框颜色设置 谁有ping命令或类似于ping命令的工具源代码?紧急!!!
GetExitCodeProcess( ... );
{
//char *a = getneedreplacestring( "public static void main(){ printf ( \"%s\\n\", \"hello, world!\" );}", "hello", "-HELLO-" );
//printf( "%s\n", a );
//delete []a;
//a = NULL;
STARTUPINFO si;
PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) ); // Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
"d:\\bb.exe", // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
printf( "CreateProcess failed.\n" );
return 1;
} // Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
unsigned long l;
GetExitCodeProcess( pi.hProcess, &l );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
printf( "exited with %d\n", l );
return 0;
}aa.c
main()
{
return 0;
}bb.c
main()
{
return 1;
}