C - 从文件读取后重置stdin

时间:2014-03-15 21:12:01

标签: c shell unix stdin eof

我正在构建一个(非常)最小的Unix shell,并且在提供配置文件时我在重置输入流时遇到了一些麻烦。提供文件时,我的shell会从文件中读取,直到它到达EOF为止。那时,我想从stdin读取输入。但是,我的命令解析器的功能使它在到达EOF时终止,因此在处理配置文件后shell无法继续运行。我很感激任何指导。谢谢!

编辑:参考代码

while ((pcLine = readLine(pfInput)) != NULL)
{   
  oTokens = findTokens(pcLine);
  if (oTokens != NULL)
  {  
     /* Print command from configuration file. */
     if (argc >= 2)
        printf("%s\n", pcLine);
     oCommand = newCommand(oTokens);
     if (oCommand != NULL)
     {  
        pcName = command_getName(oCommand);
        if (strcmp(pcName, "setenv") == 0)
           ish_setEnv(oCommand);
        else if (strcmp(pcName, "unsetenv") == 0)
           ish_unsetEnv(oCommand);
        else if (strcmp(pcName, "cd") == 0)
           ish_cd(oCommand);
        else if (strcmp(pcName, "exit") == 0)
           ish_exit(oCommand);
        else 
           execute(oCommand);

        freeCommand(oCommand);
     }
  }

  free(pcLine);
}

0 个答案:

没有答案