错误:sys/wait.h:没有这样的文件或目录

Tha*_*gnv 8 c c++ windows shell

我正在尝试用C编写一个简单的shell.但是我不能使用sys/wait.h.我的代码相同:

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

int main(void) {
    char command[BUFSIZ];
    int status;
    pid_t pid;

    for(;;) {
        printf("simpsh: ");
        if(fgets(command, sizeof(command), stdin) == NULL) {
        printf("\n");
        return 0;
   }

   command[strlen(command) - 1] = '\0';
   if((pid = fork()) == 0)
   execlp(command, command, 0);

   while(wait(&status) != pid)
   continue;

   printf("\n");
   }
Run Code Online (Sandbox Code Playgroud)

}

我正在使用dev-C++,结果是:

[Error] sys/wait.h: No such file or directory
Run Code Online (Sandbox Code Playgroud)

这里有什么不对?如果有人建议我用C或C++创建一个简单的shell,请给我一些链接或代码.谢谢!

som*_*one 5

来自http://sourceforge.net/p/dev-cpp/discussion/48211/thread/e32720b4

TextTiling/util.c:8:22:sys/wait.h:没有这样的文件或目录TextTiling/util.c:26:21:sys/vfs.h:没有这样的文件或目录

这些是特定于操作系统的文件,但不是Windows标头.Windows不完全支持POSIX API.您可能需要对代码进行一些移植以使其在Windows上编译和运行.

您可能会有更多的运气在其预期的环境中构建它(Linux或OSX可能,无论是类UNIX环境).你可能可以在Cygwin下构建它,但这是一个坚果的大锤.

一个简单的(ish)解决方案是在虚拟机下运行Linux(例如,使用VMWare的免费VMPlayer或VMServer工具).然后在VM中构建并运行代码.VM可以通过虚拟网络访问Windows计算机,因此如果您愿意,您仍然可以在Windows环境中获取结果和数据.

在一个不同的问题上,当项目位于其安装目录(C:\ Dev-Cpp)的子文件夹中时,Dev-C++有时(并且显然是随机的)会失败.