i am using the folowing code to launch the new process in Linux
pid_t processID;
char *argV[] = {"192.168.1.40",(char *) 0};
int status = -1;
status = posix_spawn(&processID,"/home/user/application",NULL,NULL,argV,environ);
if(status == 0)
std::cout<<"Launched Application";
else
std::cout<<"Launching application Failed";
Application did launches but says no command line argument. What is the error in posix_spawn arguments?
From the posix_spawn
manual page:
The argument argv is a pointer to a null-terminated array of character pointers to null-terminated character strings. These strings construct the argument list to be made available to the new process. At least argv[0] must be present in the array, and should contain the file name of the program being spawned, e.g. the last component of the path or file argument.
What's happening is that in the launched process, argv[0]
will be 192.168.1.40
instead of the name of the executable, and there are no arguments to the program after that.
so change:
char *argV[] = {"192.168.1.40",(char *) 0};
to:
char *argV[] = {"/home/user/application", "192.168.1.40",(char *) 0};
The behaviour of the argv array is mentioned more explicitly later on:
When a program is executed as a result of a posix_spawn() or posix_spawnp() call, it is entered as follows:
main(argc, argv, envp)
int argc;
char **argv, **envp;
where argc is the number of elements in argv (the ''arg count'') and argv points to the array of character pointers to the arguments themselves.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With