C中调用带参数的exe并接收返回值

test.exe

[c-sharp]  view plain copy
  1. #include<stdio.h>  
  2. #include<string.h>  
  3. int main(int argc, char* argv[])  
  4. {  
  5.  return 0;  
  6. }  

 获取test.exe的返回值

[c-sharp]  view plain copy
  1. #include "stdafx.h"  
  2. #include "windows.h"  
  3. int main(int argc, char* argv[])  
  4. {  
  5.     DWORD    dwExitCode = -1;  
  6.   
  7.     STARTUPINFO si;  
  8.     PROCESS_INFORMATION pi;  
  9.       
  10.     ZeroMemory( &si, sizeof(si) );  
  11.     si.cb = sizeof(si);  
  12.     ZeroMemory( &pi, sizeof(pi) );  
  13.       
  14.     // Start the child process.   
  15.     if( !CreateProcess( "E://test.exe", // an exe file.   
  16.         "hello.txt",        // parameter for your exe file.   
  17.         NULL,             // Process handle not inheritable.   
  18.         NULL,             // Thread handle not inheritable.   
  19.         FALSE,            // Set handle inheritance to FALSE.   
  20.         0,                // No creation flags.   
  21.         NULL,             // Use parent's environment block.   
  22.         NULL,             // Use parent's starting directory.   
  23.         &si,              // Pointer to STARTUPINFO structure.  
  24.         &pi )             // Pointer to PROCESS_INFORMATION structure.  
  25.         )   
  26.     {  
  27.         MessageBox(NULL, "CreateProcess failed.","ERROR",NULL );  
  28.     }  
  29.       
  30.     // Wait until child process exits.  
  31.     WaitForSingleObject( pi.hProcess, INFINITE );  
  32.       
  33.     GetExitCodeProcess(pi.hProcess,&dwExitCode);  
  34.       
  35.     printf("Exit code : %d/n",dwExitCode);  
  36.       
  37.     // Close process and thread handles.   
  38.     CloseHandle( pi.hProcess );  
  39.     CloseHandle( pi.hThread );  
  40.       
  41.     return 0;  
  42.   
  43. }  

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值