| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2534 人关注过本帖
标题:C中调用带参数的exe文件并接收返回值
只看楼主 加入收藏
yushu271828
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-1-12
收藏
 问题点数:0 回复次数:4 
C中调用带参数的exe文件并接收返回值
C中如何调用带参数的exe文件并接收返回值?哪位高手有没有相关的代码?谢了!
搜索更多相关主题的帖子: exe文件 返回值 参数 代码 
2008-01-12 13:31
xianshizhe111
Rank: 1
等 级:新手上路
帖 子:1451
专家分:0
注 册:2007-12-8
收藏
得分:0 
/*帮写一个下回自己写*/
/*在(MS-DOS)窗口中运行或在TC的(DOS)壳下运行*/
#include<stdio.h>
#include<string.h>
int main(int argc,char *argv[])  /*生成EXE之后 输入文件名 如:my abcde china  三个串*/ /*(my)为文件名*/
{
    int i;
    char tem[2]=" ";
    char string[100]="I like ";
    for(i=1;i<=argc;i++)
       {strcat(string,argv[i]);
    strcat(string,tem);}
    puts(string);
    return 0;
}
2008-01-12 14:52
VxWorks
Rank: 3Rank: 3
来 自:WindRiver
等 级:论坛游民
威 望:6
帖 子:859
专家分:68
注 册:2007-11-24
收藏
得分:0 
#include <windows.h>
#include <stdio.h>
int main( void )
{
    DWORD    dwExitCode;

    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );

    // Start the child process.
    if( !CreateProcess( "C:\\WINNT\\SYSTEM32\\notepad.exe", // an exe file.
        "notepad  hello.txt",        // parameter for your exe file.
        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.
    )
    {
        MessageBox(NULL, "CreateProcess failed.","ERROR",NULL );
    }

    // Wait until child process exits.
    WaitForSingleObject( pi.hProcess, INFINITE );

    GetExitCodeProcess(pi.hProcess,&dwExitCode);

    printf("Exit code : %d\n",dwExitCode);

    // Close process and thread handles.
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );

    return 0;
}

为了防止世界被破坏,为了守护世界的和平,贯彻爱与真实的邪恶,可爱又迷人的反派角色,VxWorks!
Don't ask me any question.I'm just here to buy soy sauce.
2008-01-12 15:33
zbqf109
Rank: 1
等 级:新手上路
帖 子:289
专家分:0
注 册:2006-12-31
收藏
得分:0 
嗯,楼上不错,不愧“VxWorks”这个ID

坚决不跟用TC的人打交道!
2008-01-12 16:18
yushu271828
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-1-12
收藏
得分:0 
回复 3# 的帖子
多谢!果然是高手!
2008-01-12 17:13
快速回复:C中调用带参数的exe文件并接收返回值
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014173 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved