系统(“history > wow.history”)未编辑我的文件

系统(“history > wow.history”)未编辑我的文件

我的文件也在一个分叉的子文件中。如果这有帮助的话。我想做的是让系统将历史记录复制到文本文件中。尽管每次我执行它时。文件仍然是空的。当我运行系统(“history > wow.history”)时,它只会给我 sh:1:未找到历史记录。

File *fp=fopen("wow.history","w+");
if(fp ==NULL)
printf("could not open the file specified")
exit(1);
else
system("history > wow.history");

我试图让它将其复制到文件中,而无需用户输入任何内容。

答案1

“history”命令内置于您所使用的 shell 中,不是外部可执行文件。因此,它无法通过 system() 调用来执行。

相关内容