| IWishIKnew (460) | |
yeah yeah, system is bad. But the fact of the matter is that everyone that has spoken that statement has not suggested an alternative to it. So, I ask you now: Is there an alternative to useing System()? I will not download new libraries, etc...System Specs: -Win7 -MinGW + Codeblocks I believe that's all you need to know to answer my question. If you need any more information, please ask. This is not homework/schoolwork, I am doing this in my own time, and useing the internet to help. All of your advice is very much appreciated!! | |
|
|
|
| andywestken (1950) | |
|
:-) system() IS intrisically evil. But we need to know what you're using it for to be able to propose an alternative. Andy | |
|
Last edited on
|
|
| Moschops (5956) | ||
The fact of the matter is that you just didn't look. :) | ||
|
Last edited on
|
||
| modoran (1100) | |
| Always use CreateProcess() when using windows. | |
|
|
|
| IWishIKnew (460) | |
| I tried Create process and it either has trouble compileing, or just doesn't work (no effect). Don't ask me why... | |
|
|
|
| naraku9333 (919) | |
| Show how you are using it, CreateProcess does work. | |
|
|
|
| IWishIKnew (460) | |
CreateProcess("Minecraft.exe");
CreateProcess("taskkill /im wahoo.exe /f");Assuming the .exe is in the same folder as my program. | |
|
Last edited on
|
|
| naraku9333 (919) | |
|
Did you even attempt to look up the documentation? This has an example of how it is used http://msdn.microsoft.com/en-us/library/ms682512(VS.85).aspx | |
|
Last edited on
|
|
| IWishIKnew (460) | |
|
Yes, except WinAPI is way over-complicated. The documentation is hardly understandable to me.... http://www.goffconcepts.com/techarticles/development/cpp/createprocess.html http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx Mabey an explanation is in order? | |
|
Last edited on
|
|
| naraku9333 (919) | |||
| |||
|
|
|||
| IWishIKnew (460) | |
| thanks. I will study your example and ask any questions I may have. | |
|
|
|
| modoran (1100) | |
|
Don't mean to be rude, but naraku example is not recommended to use. It will work without issues in this particular case, but it will have problems in others, especiaaly in paths with spaces. Read MSDN documentation for how exactly CreateProcess works. The recommended way is to always use NULL as first argument and use full path and command line arguments enclosed in quotes as second parameter for CreateProcess. There are numerous examples on the web. Also the second argument must be a writable string, not a constant string if you use Unicode version of CreateProcess. | |
|
|
|
| naraku9333 (919) | |||
|
@modoran Looks like I missed some bits when I skimmed through the documentation
Pretty good example of why reading the documentation fully is so important. | |||
|
Last edited on
|
|||
| andywestken (1950) | |||
Actually, this statement is incorrect. Microsoft actually recommends the opposite, for security reasons (the problem they are referring to is paths with spaces). From the MSDN entry on CreateProcess():
You should only ever pass NULL as the first parameter by choice if you need to support 16-bit apps. Andy | |||
|
Last edited on
|
|||
| IWishIKnew (460) | |
| So..... System()? | |
|
|
|
| andywestken (1950) | |
| What's System() ?? | |
|
|
|
| Moschops (5956) | ||
should not be used. Yes, we've covered that. | ||
|
|
||