我写了下面的代码,但总是得到输出:“ERROR!” (execv函数没有预定返回)我的execv()函数在linux下不工作ubuntu
我在做什么错?
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <math.h>
#include <string.h>
#include <malloc.h>
#include "LineParser.h"
#define LOCATION_LEN 200
char* getL(void);
int main(int argc,char *argv[])
{
char *loc = getL();
char *args[] = {loc,"ls",NULL};
int i;
execv(args[0],args);
printf("ERROR!");
free(loc);
}
char* getL(void)
{
char *buff = (char**)malloc(sizeof(char)*LOCATION_LEN);
getcwd(buff,LOCATION_LEN);
return buff;
}
首先,从'execv'返回检查errno。然后检查你传递的参数。 – Duck 2014-10-05 14:38:12
execv返回-1 – Roni 2014-10-05 14:47:53
当然它返回-1。使用'errno'和'strerror'或'perror'来解释为什么......也就是你的参数。 – Duck 2014-10-05 15:49:35