zoukankan      html  css  js  c++  java
  • C中调用带参数的exe并接收返回值

    test.exe

    [c-sharp] view plaincopy
    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 plaincopy
    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. }  

  • 相关阅读:
    idea中如何配置tomcat
    onselectstart属性解决双击出现的蓝色区域
    (二十二)数组的最大值和最小值
    (二十一)数组的初始化
    (二十)两种数据类型的对比
    (十九)数组的内存分配
    (十八)数组概述
    (十六)函数的重载
    (十七)自定义函数
    (十五)函数的入栈和出栈
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13318699.html
Copyright © 2011-2022 走看看