我试图使用其可执行文件运行C程序,但没有任何反应

时间:2010-11-08 19:10:46

标签: c linux

尽管使用gcc编译器我双击了二进制可执行文件,但似乎没有发生任何事情 任何人都可以告诉我是否可能,如何通过双击二进制可执行文件来运行我的程序。

#include  <stdio.h>
#include  <stdlib.h>
#include  <errno.h>
#include  <unistd.h>
#include  <sys/types.h>
#include  <sys/wait.h>
#include  <string.h>
int main(void)
{
    pid_t pid;
    char ch;
    switch(pid = fork()) {
    case -1:
         perror("fork"); /* something went wrong */
         exit(1);         /* parent exits */
    case 0:
     FILE *fpaste,*fcopy;
     fpaste=fopen(xyz,"w");
     fcopy=fopen(abc,"r");
     while(1)  
         {  
            ch = getc(fcopy);  
            if(ch==EOF)  
        {  
            break;  
        }  
        else  
             putc(ch,fpaste);  
     }  
     fclose(fcopy); 
     fclose(fpaste);
     }
     exit(0);
   default:
         printf("PARENT: I'm outta here!\n");
    }
    return 0;
}

我只是在玩fork()然后我突然遇到了这个疑问。代码运行正常我也检查了输出。任何人都可以告诉我为什么和做什么。我还检查了我的其他c程序..同样的事情..

2 个答案:

答案 0 :(得分:4)

嗯,这取决于程序的功能。如果它是一个控制台程序,那么只要双击它就不会做任何事情。您需要在终端中运行它。这可能在设置中可用,或者您只需打开一个终端并在那里运行。

答案 1 :(得分:0)

当您双击该文件时,它可能尝试启动但失败了。尝试从终端启动它,看看你得到了什么错误。例如,它可能无法找到共享库。