• 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. }  

  • 相关阅读:
    Mathematica查看内部定义
    Mathematica绘制曲面交线方法
    Mathematica新特性Inactive, 求解复杂微分方程
    Mathematica修改默认字体
    Mac系统下lipo, ar, nm等工具的使用简介
    centos8 安装php7.2以及php-fpm
    mysql8.0创建用户只能访问某一个数据库
    CentOS 7 yum安装 RabbitMQ
    Linux服务器PHP+MYSQL环境配置优化提升网站运行效率
    PHP 7.1安装xhprof进行性能分析
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13318699.html
Copyright © 2020-2023  润新知