Questions tagged [execv]

int execv(const char *path, char *const argv[]); Like all of the exec functions, execv replaces the calling process image with a new process image. This has the effect of running a new program with the process ID of the calling process. The command-line arguments are passed to the function as an array (Vector) of pointers.

The POSIX standard declares exec functions in the unistd.h header file, in C language. The same functions are declared in process.h for DOS and Microsoft Windows.

When execv() is successful, it doesn't return; otherwise, it returns -1 and sets errno.

185 questions
0
votes
2 answers

Using Scanf() in child process executed via execv not working

I am executing a really simple program which takes input in integer from user using scanf. I execute this program as a child program via fork() and execv.The child program never takes input from user.Any help would be appreciated. #include…
0
votes
1 answer

dup2() is preventing output

my code is pasted below. I'm trying to use dup2 to redirect my output to file. if I use it to redirect it works fine (if I remove the comments), output in file and not on stdout. ex: ls > test , results in ls outputting to test. the problem…
d0m1n1c
  • 157
  • 4
  • 16
0
votes
1 answer

after execv, the contents in pipe buffer disappear

There are two process, parent process and child process There are some data in parent process stdin. The content is: the 1 line the 2 line the 3 line the 4 line The parent process code: //parent fgets(buffer, 1000, stdin); printf("I have data:%s",…
0
votes
3 answers

Pipe is not receiving all output from child process

I wanted to open up a pipe to a program and read output from it. My initial inclination was to use popen(), but the program takes a number of options, and rather that fighting with shell quoting/escaping, I decided to use a combination of pipe(),…
ray
  • 31
  • 4
0
votes
2 answers

Sending Output of One Command (execv) to Another

void execute_command_pipe(char * command_from, char * command_to, char ** args_from, char ** args_to) { pipe(pipefd); int pid = fork(); close(pipefd[0]); if (pid == 0) { //close(STDOUT_FILENO); dup2(pipefd[1],…
Tyler Sebastian
  • 9,067
  • 6
  • 39
  • 62
0
votes
2 answers

Execv failing even when command is available

I'm trying to call execv after manually saerching for the program to execute. In my case, c is a struct which has args as an array of strings having the arguments passed while receiving input. nargs is the number of arguments. c->args[0] would…
Torpedo
  • 171
  • 1
  • 3
  • 10
0
votes
1 answer

Execv for own terminal

I am currently writing my own terminal in C. I found out, that there is multiple variants of the exec() methode, that i can use. Its simple occurance lead me to use execv(): int main(int argc , char* argv[]){ char* dir = getcwd(NULL, 0); …
Torhan Bartel
  • 550
  • 6
  • 33
0
votes
1 answer

Shared variable between different executables in Linux

What I want to do is to create a globally shared variable to be accessed by different processes. I want the child process to be replaced by an existing executable. UPDATE: I think this is the solution. The code is borrowed from here. But since…
towi_parallelism
  • 1,421
  • 1
  • 16
  • 38
0
votes
1 answer

Program crash in forking process with pipes

I'm writing a basic shell for course homework that will find a command in the given list of paths, and execute the command. It is also meant to handle pipes. However, when I fork a child process, I get a "Write error : Broken Pipe" message in gdb,…
0
votes
1 answer

how to call 2 or more shellexecute functions in a program

I am a beginner in winapi c++ on windows platform, i need to execute 3 exe files,i.e the installation programs, in one single program. i used shellexecute, exec v, system calls but all are exiting the program after the first program installation,…
Paul
  • 39
  • 1
  • 9
0
votes
1 answer

Redirect output of process ran by execv

Possible Duplicate: redirecting output to a file in C I'm running a process as follows: char* [NUM]; char[0] = processName; char[1] = arg0; ... char[NUM] = 0; execv(args[0],args); The question is how I can make it redirect its output to…
Alon_T
  • 1,430
  • 4
  • 26
  • 47
0
votes
3 answers

Reading commands from cmd line, and executing them in C

I'm writing a program to take user input from the command line (linux/unix commands), and execute them within my program. My steps so far: Ask user for number of commands input Fork() to create child process Output Child PID and Parent PID Allow…
Baelix
  • 261
  • 2
  • 7
  • 17
0
votes
1 answer

Daemon under linux fails to launch app with execv

We have a command and control daemon running under Fedora 16 that provides various services, including starting one of our ancillary applications. This has been working for us for quite some time. In fact it still works - on some systems. The…
Arunas
  • 1,282
  • 1
  • 11
  • 17
0
votes
1 answer

How to wait for a child that respawns itself with os.execv() on win32?

I have some code that uses pip to bootstrap a Python envionment for out build process: this is a lovely way of ensuring we get proper isolation of the build requirements from the rest of the host system, and helping us get more consistent build…
jkp
  • 78,960
  • 28
  • 103
  • 104
0
votes
1 answer

How to return immediately from forked child process in Linux?

I am not familar with linux C development. my code: .... if((pid=fork())==0){ //child process //start a process, may be need to change execv to other call execv (workdir , args); }else if (pid<0){ ... }else{ ... } What I want to do is…
Ben Xu
  • 1,279
  • 4
  • 13
  • 26