Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //child.exe
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- int main(int argc, char *argv[])
- {
- std::cout << "------------------------" << std::endl;
- std::cout << "Child started" << std::endl;
- char *USERNAME = getenv("USERNAME");
- char *COMPUTERNAME = getenv("COMPUTERNAME");
- char *MYPATH = getenv("MYPATH");
- std::cout << "USERNAME: " << USERNAME << std::endl;
- std::cout << "COMPUTERNAME: " << COMPUTERNAME << std::endl;
- std::cout << "MYPATH: " << MYPATH << std::endl;
- system("pause");
- std::cout << "Child destroyed" << std::endl;
- std::cout << "------------------------" << std::endl;
- return 0;
- }
- //parent_3_1.exe
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- #include <process.h>
- void main(int argc, char *argv[])
- {
- std::cout << "Parent_3_1 started" << std::endl;
- putenv("MYPATH=D:\\TEMP");
- std::cout << "Parent_3_1 call <spawnle(int mode, char *fname, char *arg0, ..., char *argN, NULL, char *envp[ ])> child.exe" << std::endl;
- if (spawnle(P_WAIT, "child.exe", argv[0], NULL, NULL, _environ) == -1)
- std::cout << "Error: " << errno << std::endl;
- else
- std::cout << "All is well" << std::endl;
- std::cout << "Parent_3_1 destroyed" << std::endl;
- system("pause");
- }
- //parent_3_2.exe
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- #include <process.h>
- void main(int argc, char *argv[])
- {
- std::cout << "Parent_3_2 started" << std::endl;
- putenv("USERNAME=PARENT_2");
- putenv("COMPUTERNAME=OS-LAB-3");
- putenv("MYPATH=D:\\TEMP");
- std::cout << "Parent_3_2 call <spawnle(int mode, char *fname, char *arg0, ..., char *argN, NULL, char *envp[ ])> child.exe" << std::endl;
- if (spawnle(P_WAIT, "child.exe", argv[0], NULL, NULL, _environ) == -1)
- std::cout << "Error: " << errno << std::endl;
- else
- std::cout << "All is well" << std::endl;
- std::cout << "Parent_3_2 destroyed" << std::endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment