Hello, and thank you for your interest in this disscussion. Here is my problem: I need to be able to run .EXE files from my console-based application. Here is the biggest bump in the road: The path is in a string variable. How do I run it? Please post code. Thank you.
							
						
					Running .EXEs From A String Path
				
					Collapse
				
			
		
	X
- 
	
	
	
		
	
	
	
		
	
	
	
	
	
	
	
	
	Tags: None
- 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 Take a look at exec* and spawn* functions families.Originally posted by compman9902Hello, and thank you for your interest in this disscussion. Here is my problem: I need to be able to run .EXE files from my console-based application. Here is the biggest bump in the road: The path is in a string variable. How do I run it? Please post code. Thank you.
 
 I'm prety sure that u can do this all by u self! ;)
 
 Savage
- 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 Any particular direction you'd like to point me in?Originally posted by SavageTake a look at exec* and spawn* functions families.
 
 I'm prety sure that u can do this all by u self! ;)
 
 SavageComment
- 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 Now,that depends on u:Do u wish that ur main programme terminate when another app is calld or not?Originally posted by compman9902Any particular direction you'd like to point me in?
 
 If u wish to terminate ur main programm use execlp,it allows u to serach for app in that directory specifed by path(e.g)
 
 char *path="C:\\WIND OWS\\NOTEPAD.EX E;
 execlp(path,pat h,NULL);
 
 SavageComment
- 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 what include do I use?Originally posted by SavageNow,that depends on u:Do u wish that ur main programme terminate when another app is calld or not?
 
 If u wish to terminate ur main programm use execlp,it allows u to serach for app in that directory specifed by path(e.g)
 
 char *path="C:\\WIND OWS\\NOTEPAD.EX E;
 execlp(path,pat h,NULL);
 
 SavageComment
- 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 This is just not working for me. Could you just point me tword a web tutorial for this command?Originally posted by SavageIf u are using windows include process.h if u are using unix include unistd.h
 
 SavageComment
- 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 Enable your program to load and run other files (child processes)
 
 Use these execl... functions when you know how many separate arguments
 you'll have:
 
 Declaration:
 int execl (char *path, char *arg0, ..., NULL);
 int execle (char *path, char *arg0, ..., NULL, char **env);
 int execlp (char *path, char *arg0, ...);
 int execlpe(char *path, char *arg0, ..., NULL, char **env);
 
 Use these execv... functions when you don't know in advance how many
 separate arguments you will have:
 
 Declaration:
 int execv (char *path, char *argv[]);
 int execve (char *path, char *argv[], char **env);
 int execvp (char *path, char *argv[]);
 int execvpe(char *path, char *argv[], char **env);
 
 Remarks:
 When an exec... call succeeds, the child process overlays the parent
 process. There must be sufficient memory available for loading and executing
 the child process.
 
 The l, v, e, and p suffixes added to "exec" specify certain capabilities of
 the exec... function.
 
 Argument ³ What It Is/Does
 path ³ File name of the called child process
 argN ³ Argument pointer(s) passed as separate arguments
 argv[N] ³ Argument pointer(s) passed as an array of pointers
 env ³ Array of character pointers.
 
 The exec... functions search for path using the
 standard DOS search algorithm.
 
 When an exec... function call is made, any open files remain open in the
 child process.
 
 Return Value:
 On success, the functions do not return.
 On error, the functions return -1 and set
 errno to one of the following:
 E2BIG Arg list too long
 EACCES Permission denied
 EMFILE Too many open files
 ENOENT Path or file name not found
 ENOEXEC Exec format error
 ENOMEM Not enough core
 
 ***************
 execv example
 ***************
 #include <process.h>
 #include <stdio.h>
 #include <errno.h>
 
 int main(int argc, char *argv[])
 {
 int i;
 
 printf("Command line arguments:\n");
 for (i=0; i < argc; i++)
 printf("[%2d] : %s\n", i, argv[i]);
 
 printf("About to exec child with arg1 arg2 ...\n");
 execv("CHILD.EX E", argv);
 
 perror("exec error");
 exit(1);
 return 0;
 }Comment
- 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 Okay, all I need is to make a seperate program run from my c++ console based program, where the file path is in a string variable.Originally posted by nearestniladri2 003Enable your program to load and run other files (child processes)
 
 Use these execl... functions when you know how many separate arguments
 you'll have:
 
 Declaration:
 int execl (char *path, char *arg0, ..., NULL);
 int execle (char *path, char *arg0, ..., NULL, char **env);
 int execlp (char *path, char *arg0, ...);
 int execlpe(char *path, char *arg0, ..., NULL, char **env);
 
 Use these execv... functions when you don't know in advance how many
 separate arguments you will have:
 
 Declaration:
 int execv (char *path, char *argv[]);
 int execve (char *path, char *argv[], char **env);
 int execvp (char *path, char *argv[]);
 int execvpe(char *path, char *argv[], char **env);
 
 Remarks:
 When an exec... call succeeds, the child process overlays the parent
 process. There must be sufficient memory available for loading and executing
 the child process.
 
 The l, v, e, and p suffixes added to "exec" specify certain capabilities of
 the exec... function.
 
 Argument ³ What It Is/Does
 path ³ File name of the called child process
 argN ³ Argument pointer(s) passed as separate arguments
 argv[N] ³ Argument pointer(s) passed as an array of pointers
 env ³ Array of character pointers.
 
 The exec... functions search for path using the
 standard DOS search algorithm.
 
 When an exec... function call is made, any open files remain open in the
 child process.
 
 Return Value:
 On success, the functions do not return.
 On error, the functions return -1 and set
 errno to one of the following:
 E2BIG Arg list too long
 EACCES Permission denied
 EMFILE Too many open files
 ENOENT Path or file name not found
 ENOEXEC Exec format error
 ENOMEM Not enough core
 
 ***************
 execv example
 ***************
 #include <process.h>
 #include <stdio.h>
 #include <errno.h>
 
 int main(int argc, char *argv[])
 {
 int i;
 
 printf("Command line arguments:\n");
 for (i=0; i < argc; i++)
 printf("[%2d] : %s\n", i, argv[i]);
 
 printf("About to exec child with arg1 arg2 ...\n");
 execv("CHILD.EX E", argv);
 
 perror("exec error");
 exit(1);
 return 0;
 }Comment
- 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 The issue has been resolved, thank you for all of your helpOriginally posted by compman9902Okay, all I need is to make a seperate program run from my c++ console based program, where the file path is in a string variable.
 all I did was add quotes to the beggining and end of the path, then make the path into an "old style string", then put it into the system command. Easy, simple, and working.Comment
Comment