execvp

After execvp returns, why doesn't my program pick up where it left off?

I have a block of code like this that runs as a child thread: if(someVar == 1){ doSomeStuff; _exit(0) } else execvp(*(temp->_arguments), temp->_arguments); printf("I'm done\n"); When I run the program with someVar == 1, I understand that the _exit(0) call kills my thread. However, when it's set to 0, why doesn't the program contin...

Trying to use execvp() in C with user input in unix

I'm trying to make a program that will prompt the user for a command, then use exec to execute that command. For instance if they gave me "ls -la" I would have to execute that command. I've tried the following code: #include <stdio.h> #include <unistd.h> #include <string.h> int main() { int ret, num_args; printf("Enter numbe...

execv, wait, Unix programming, How to wait for a child

Hi I'm working on a unix shell and I'm running into two problems. I was wondering if any of you could help me out. My first problem is that the shell is not waiting for the child process to terminate. I can actually go type more commands while the child process is running. My second problems is in the following two lines. I'm not getting...

How to get forkpty/execvp() to properly handle redirection and other bash-isms?

Hi all, I've got a GUI C++ program that takes a shell command from the user, calls forkpty() and execvp() to execute that command in a child process, while the parent (GUI) process reads the child process's stdout/stderr output and displays it in the GUI. This all works nicely (under Linux and MacOS/X). For example, if the user enters...

Does control return after "execvp()" ?

if(pid == 0) { execvp(cmd, args); // printf("hello"); // apparently, putting this or not does not work. _exit(-1); } else { // parent process work } "execvp()" replaces the current program with the to-be-execed program (of course in the same process context). So, putting, say, any printf() calls after execvp() ...

char ** nargv being empty but do not know why

Hi, I am trying to do something quite easy: fill an char** with arguments I want to use in a execvp call in C. This is how I am doing: if(argc >=1) { *nargv = "--action"; while(argc--) { printf("nargv1 => %s \t argv1 => %s \n", *nargv, *argv); *++nargv = *argv++; printf("nargv2 =>...

Waiting for execvp in main

int main() { ... if(!fork()) { execvp(cmdName,cmdParam); } printf("In main()..."); return(0); } Assuming I have correctly passed the cmdName & cmdParam arguments, how do I wait for the process created by execvp to finish, before resuming the execution of main()? Does the execvp() create a proces...

C - passing an unknown command into execvp()

I'm writing a fake shell, where I create a child process and then call execvp(). In the normal shell, when I enter an unknown command such as 'hello' it returns 'hello: Command not found.' However, when I pass hello into execvp(), it doesn't return any error by default and just continues running the rest of my program like nothing happen...