jodyl
asked on
Using CreateProcess() and spawn functions
I haven't used these before, so I'm not sure what I might be doing wrong.
Spawn functions:
I'm trying to use the spawn functions so I can start an application (child process) and put the calling application (parent) in suspension while the child process runs.
I'm able to get the child process to start ok, but not with any command line parameters. And the only way I can get them to work is to give the name of the application in both the command name and argument strings. If I add the command line parameters, the child process doesn't start up.
CreateProcess():
I need to use this so I can get the handle of the process back so I can terminate it from parent process.
Any suggestions as to things that are frequently done incorrectly or things that MUST be done in a certain way for these functions would be greatly appreciated.
Jody
Spawn functions:
I'm trying to use the spawn functions so I can start an application (child process) and put the calling application (parent) in suspension while the child process runs.
I'm able to get the child process to start ok, but not with any command line parameters. And the only way I can get them to work is to give the name of the application in both the command name and argument strings. If I add the command line parameters, the child process doesn't start up.
CreateProcess():
I need to use this so I can get the handle of the process back so I can terminate it from parent process.
Any suggestions as to things that are frequently done incorrectly or things that MUST be done in a certain way for these functions would be greatly appreciated.
Jody
Hi jody,
I tried the following & it worked fine for me
spawnl( _P_WAIT, "c:\\winnt\\system32\\note pad.exe", "notepad.exe", "c:\\temp\\profiled.txt", NULL );
ie. My app launched Notepad giving it the file profiled.txt
Notes:
The last parameter to spanwl() should be NULL.
The third parameter should be the name of the app (not the first argument to the app)
I remember while programming under DOS, argv[0] contained the name of the app & the arguments actually started from argv[1]... I guess thats the reason the first argument (ie. spawnl() param 3) should be the name of the app!?
btw, which platform are you working under? I tried the above under Windows NT 4.0.
Hope this helps, I will give you some info regarding CreateProcess() as soon as I get some time
Wilfred
I tried the following & it worked fine for me
spawnl( _P_WAIT, "c:\\winnt\\system32\\note
ie. My app launched Notepad giving it the file profiled.txt
Notes:
The last parameter to spanwl() should be NULL.
The third parameter should be the name of the app (not the first argument to the app)
I remember while programming under DOS, argv[0] contained the name of the app & the arguments actually started from argv[1]... I guess thats the reason the first argument (ie. spawnl() param 3) should be the name of the app!?
btw, which platform are you working under? I tried the above under Windows NT 4.0.
Hope this helps, I will give you some info regarding CreateProcess() as soon as I get some time
Wilfred
ASKER
I'm using Win95.
I had not tried it exactly like yours,
spawnl( _P_WAIT, "c:\\winnt\\system32\\note pad.exe", "notepad.exe", "c:\\temp\\profiled.txt", NULL
);
I'd tried this:
spawnl( _P_WAIT, "c:\\windows\\notepad.exe" , "c:\\temp\\temp.txt", NULL );
and this:
spawnl( _P_WAIT, "c:\\windows\\notepad.exe" , "c:\\windows\\notepad.exe" , NULL );
I tried what you suggested and it worked fine. I didn't think about argv[0] being the name of the app in DOS, that makes what the help on _spawn*() says about the arguments make more sense to me now.
Thanks,
Jody
I had not tried it exactly like yours,
spawnl( _P_WAIT, "c:\\winnt\\system32\\note
);
I'd tried this:
spawnl( _P_WAIT, "c:\\windows\\notepad.exe"
and this:
spawnl( _P_WAIT, "c:\\windows\\notepad.exe"
I tried what you suggested and it worked fine. I didn't think about argv[0] being the name of the app in DOS, that makes what the help on _spawn*() says about the arguments make more sense to me now.
Thanks,
Jody
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked great, was able to open and close the app from the parent process. My problem in both cases seems to be a misunderstanding of exactly what should be put into the application, command and argument strings.
Thanks very much for your help Wilfred.
Jody
Thanks very much for your help Wilfred.
Jody
ASKER
Jody