[c fwrite()如果我使用execl()则不起作用

问题描述 投票:0回答:1

如果我用execl删除行,则fwrite将再次开始工作。可能是什么问题?

#include <stdio.h> 
#include <sys/types.h> 
#include <unistd.h> 
#include <stdlib.h>
#include <sys/wait.h> 

int main()
{
    FILE *fptr;
    fptr = fopen("./belenkas", "w+");
    fwrite("echo $(whoami)", 1, sizeof("echo $(whoami)"), fptr);
    execl("/bin/sh" ,"sh" , "./belenkas", NULL);

}
c exec
1个回答
0
投票

fclose(fptr)解决了。谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.