gpt4 book ai didi

c - 使用 execvp 声明范围错误

转载 作者:行者123 更新时间:2023-11-30 19:03:08 27 4
gpt4 key购买 nike

我正在编写一个 C 程序,该程序接收用户在控制台 (Linux) 中编写的输入,使用收到的参数创建一个 vector ,并使用子 Shell 执行它们。我在尝试编译它时收到所有这些错误/警告。可能与子 Shell 创建有关,但我不确定。怎么了?

int main(int argc, char *argVector[])
{
char command[100];
int status, pid;

while (1)
{
GetCommand( command );
if(strcmp(command, "quit\n") == 0) break;
if ( ( pid = fork() ) < 0 )
{
printf("%s\n", "Erro ao realizar fork");
break;
}
if( pid == 0 )
{
makeArgVector(command,argVector);
if(execvp(argvector[0],argVector) < 0 )
{
printf("Erro ao executar comando");
break;
}
}else
wait(&status);
}
return 0;
}

一旦我尝试编译程序,就会弹出此错误/警告:

wait(&status) was not declared in this scope.

最佳答案

Wait() 在 wait.h 文件中声明。所以我们必须包含这个头文件,如下所示,以便编译器从头文件中获取声明。

#include <sys/wait.h>

关于c - 使用 execvp 声明范围错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54565085/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com