Sponsored Content
Full Discussion: execvp and execlp?
Top Forums Programming execvp and execlp? Post 6342 by Perderabo on Tuesday 4th of September 2001 09:33:23 AM
Old 09-04-2001
With execvp you need an argv array already built. So a program like:
Code:
#include "stdlib.h"  /** vb is eating my angle brackets **/
main(argc,argv)
int argc;
char **argv;
{
      execvp(*++argv, argv);
}

will simply pass its arguments to execvp.

With execlp you do stuff like:
execlp("echo", "echo", "one", "two", NULL);
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

execv () vs execvp ()

what's the difference between the two? (3 Replies)
Discussion started by: hurleyint1386
3 Replies

2. UNIX for Dummies Questions & Answers

problem with execvp

i am having an application that contains a push button. On the click of this push button i want to call a executable file using execvp function block fo2 push button { char *args; args=NULL; execvp("/home2/xyz/app1.exe",args) } but after compilation when i press this button the... (3 Replies)
Discussion started by: kunu
3 Replies

3. UNIX for Dummies Questions & Answers

execvp:ar:Arg list too long -> while linking

I get this error : execvp:ar:Arg list too long when i am trying to link the .obj files created on unix box. Any resolution to this? Thanks Mohit (1 Reply)
Discussion started by: mohitp
1 Replies

4. Programming

after executing execvp()... program hangs up

Hi , I m actually trying to implement pipes program,but after executing the execvp(),my program is getting hanged up :mad: Actaully i m getting the desired output expected from execvp()...but once results are displayed on the output screen ,program is getting hanged up values of... (3 Replies)
Discussion started by: Crab
3 Replies

5. Programming

execlp to sort

Hi, I have a very small program where I call execlp() to execute sort. Everything works fine. But sort has a -T option which can be used to specify a temporary directory. Now when I use -T with execlp() it does not work. #include <stdio.h> #include <stdlib.h> #include <string.h> #include... (4 Replies)
Discussion started by: the_learner
4 Replies

6. HP-UX

ENOENT error occurs while issueing execlp command

/************************************************************************ * * TEST NAME: setrlimitd_su.c * * PURPOSE: To verify the soft (rlim_cur) and hard (rlim_max) limit * of process RLIMIT_DATA resources correctly inherited by * the exec() system call. * * RESULT: function call should... (1 Reply)
Discussion started by: mansa
1 Replies

7. UNIX for Dummies Questions & Answers

How it work?? the execlp

int main () { int p=1; while (p>0) p=fork(); execlp("prog",prog",Null); return 0; } and thanks :b: (1 Reply)
Discussion started by: foufo07
1 Replies

8. Programming

How use exec, execlp, ....

Hello, I need to do a function in ansi c for linux that work like command cp.I try with this but doesn't work: int copy (char *src, char *dst) { ret = execlp("/bin/cp", "cp", "/home/linux/working", (char*)src,(char*)dst) return 0; } The copy function must do the next "cp origein.txt... (2 Replies)
Discussion started by: NewBe
2 Replies

9. Programming

Execvp with arguments

Hi, I'm trying to build my own little shell as an exercise. I want to run emacs from my shell so I'm using execvp() command. The problem is when I run it with arguments at background (e.g "emacs file1 &") it stays "hung" (I don't get the prompt back) while without arguments it runs ok ("emacs... (1 Reply)
Discussion started by: Rap_master
1 Replies

10. Programming

Problem with fork() and execlp process

Hello everyone, this is my first post. I have a task to use a fork to create multiple processes and then use execlp to run another program to add 2 numbers. The problem I am having is we are supposed to use the exit() call in the execlp to return the small integer. This is a bad way to... (3 Replies)
Discussion started by: Johnathan_1017
3 Replies
execl(3)						     Library Functions Manual							  execl(3)

Name
       execl, execv, execle, execlp, execvp, exect, environ - execute a file

Syntax
       execl(name, arg0, arg1, ..., argn, (char *)0)
       char *name, *arg0, *arg1, ..., *argn;

       execv(name, argv)
       char *name, *argv[];

       execle(name, arg0, arg1, ..., argn, (char *)0, envp)
       char *name, *arg0, *arg1, ..., *argn, *envp[];

       execlp(file, arg0, arg1, ..., argn, (char *)0)
       char *file, *arg0, *arg1, ..., *argn;

       execvp(file,argv)
       char *file, *argv[];

       exect(name, argv, envp)
       char *name, *argv[], *envp[];

       extern char **environ;

Description
       These  routines provide various interfaces to the system call.  Refer to for a description of their properties; only brief descriptions are
       provided here.

       In all their forms, these calls overlay the calling process with the named file, then transfer to the entry point of the core image of  the
       file.  There can be no return from a successful exec.  The calling core image is lost.

       The  name  argument is a pointer to the name of the file to be executed.  The pointers arg[0], arg[1] ...  address null-terminated strings.
       Conventionally arg[0] is the name of the file.

       Two interfaces are available.  is useful when a known file with known arguments is being called; the arguments to are the character strings
       constituting the file and the arguments; the first argument is conventionally the same as the file name (or its last component).  A 0 argu-
       ment must end the argument list.

       The version is useful when the number of arguments is unknown in advance.  The arguments to are the name of the file to be executed  and  a
       vector of strings containing the arguments.  The last argument string must be followed by a 0 pointer.

       The  version  is used when the executed file is to be manipulated with The program is forced to single step a single instruction giving the
       parent an opportunity to manipulate its state.  On VAX-11 machines, this is done by setting the trace bit in the process status longword.

       When a C program is executed, it is called as follows:
	    main(argc, argv, envp)
	    int argc;
	    char **argv, **envp;
       where argc is the argument count and argv is an array of character pointers to the arguments themselves.  As indicated, argc is convention-
       ally at least one and the first member of the array points to a string containing the name of the file.

       The argv is directly usable in another because argv[argc] is 0.

       The envp is a pointer to an array of strings that constitute the environment of the process.  Each string consists of a name, an "=", and a
       null-terminated value.  The array of pointers is terminated by a null pointer.  The shell passes an environment entry for each global shell
       variable  defined  when	the program is called.	See for some conventionally used names.  The C run-time start-off routine places a copy of
       envp in the global cell which is used by and to pass the environment to any subprograms executed by the current program.

       The and routines are called with the same arguments as and but duplicate the shell's actions in searching for an executable file in a  list
       of directories.	The directory list is obtained from the environment.

Restrictions
       If  is  called  to  execute  a  file that turns out to be a shell command file, and if it is impossible to execute the shell, the values of
       argv[0] and argv[-1] will be modified before return.

Diagnostics
       If the file cannot be found, if it is not executable, if it does not start with a valid magic number if maximum memory is exceeded,  or	if
       the  arguments  require too much space, a return constitutes the diagnostic; the return value is -1.  For further information, see Even for
       the super-user, at least one of the execute-permission bits must be set for a file to be executed.

Files
       /bin/sh	 Shell, invoked if command file found by execlp or execvp

See Also
       csh(1), execve(2), fork(2), environ(7)

								       RISC								  execl(3)
All times are GMT -4. The time now is 09:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy