I have 2 programs
(1) Program P1.EXE, which inputs a name from user, calls P2.EXE using spawnlp() and passes the name as an argument
(2) Program P2.EXE which takes the name passed from P1.EXE as an argument and displays it
My problem is that
(1) when i use P_WAIT in the spawn() it doesnt link to P2.EXE but when i use P_OVERLAY it does?? The programs are not big for any memory error to happen
(2) and when it links, the argument name is not passed on to P2.EXE
heres the code
CODE FOR P1.EXE
Code:
#include<iostream.h>
#include<process.h>
#include<conio.h>
int main()
{
char name[21];
int retval;
clrscr();
cout<<"This is P1.EXE\n";
cout<<"Enter your name : ";
cin.getline(name,20,'\n');
cout<<"P1.EXE will now try to link to P2.EXE with your name passed on as an argument.\n";
retval=spawnlp(P_OVERLAY,"P2.EXE",name,NULL);
if(retval==0)
cout<<"Linking with P2.EXE was successful.\n";
else
cout<<"Linking with P2.EXE was unsuccessful.\n";
cout<<"Exiting P1.EXE\n\n";
return 0;
}
CODE FOR P2.EXE
Code:
#include<iostream.h>
int main(int argc, char *argv[])
{
int retval;
cout<<"**************\n";
cout<<"This is P2.EXE \n";
cout<<"Link from P1.EXE established.\n";
//errchk
cout<<"\t\tARGC : "<<argc<<"\n";
for(int i=0;i<argc;i++)
cout<<"\t\tARGV["<<i<<"] : "<<argv[i]<<"\n";
switch(argc)
{
case 2:
cout<<"Your name is : "<<argv[1]<<"\n";
retval=0;
break;
case 3:
cout<<"Your name is : "<<argv[1]<<" "<<argv[2]<<"\n";
retval=0;
break;
default:
cout<<"Argument format is not correct : P2.EXE (first_name) (last_name)\n";
retval=-1;
break;
}
cout<<"Exiting P2.EXE\n";
cout<<"**************\n";
return retval;
}
Can anyone shed some light on this problem??
Heres the zip also...