【发布时间】:2020-04-07 07:59:12
【问题描述】:
我想写入我使用exec 函数创建的文本文件
到目前为止我尝试了什么:
int fd[2];
pipe(fd);
dup2(fd[1],1);
char * echo_args[] = {"/bin/echo" , "I want to write this >> ~/.filename", NULL};
execv(echo_args[0], echo_args);
这导致在终端中输出以下输出:
I want to write this >> ~/.filename
我知道在使用 echo 时通常存在格式问题分别是:
test.c:103:42: error: expected '}'
char * echo_args[] = {"/bin/echo" , ""I want to write this">> ~/.file...
^
test.c:103:25: note: to match this '{'
char * echo_args[] = {"/bin/echo" , ""I want to write this">> ~/.file...
关于我可以做些什么来解决这个问题或使用 exec 将文本写入文件的任何替代方法有什么想法吗?
另外,我知道 C 中有文件功能,不需要 exec 或任何这些,但我需要使用它。
【问题讨论】: