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

  • 相关阅读:
    jsp mysql 配置线程池
    服务端 模拟 检测 攻击。。乱写
    硕思闪客精灵 7.2 破解版
    unity UnityAwe 插件
    smartfoxserver 2x 解决 Math NAN
    unity 断点下载
    java 监听文件目录修改
    wind7 64 setup appjs
    sfs2x 修改jvm 内存
    unity ngui 解决图层问题
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13318699.html
Copyright © 2011-2022 走看看