In a console based application, how do you run a new program without closing the original. For example I open a console version of microsofts "run". The program opens the new program you type in.
In a console based application, how do you run a new program without closing the original. For example I open a console version of microsofts "run". The program opens the new program you type in.
You mean like the system() call?
No, I mean, in a program you could have something like
and the other program would appear on the screen.Code:open(a_different_program.exe);
Correct me if I'm wrong, but I'm pretty sure that's what the system() call does... if you want a console application to open in a new window, you'll have to do something like pass cmd.exe the name of the console application as an argument.
Could you give me an example.
I thought system could only be used toaccess things like "ping" that are commonly used in command prompt. I also read elsewere on this forum that system(); isn't a good command to use.
I think you may be wanting ShellExecute(), which to my knowledge is similar to system()? I don't quite know, however I do know you can do this:
To my knowledge, again which may be wrong, system() echos as if you went to start->run->cmd and you typed the text in. ( Which can probably open a new process too, if that's what you are wanting )Code:#include <windows.h> // ShellExecute() ... // The below line will open your homepage in Firefox if it's installed ShellExecute(NULL, "open", "C:\\Program Files\\Mozilla Firefox\\firefox.exe", NULL, NULL, NULL); ...
Also, if you are wanting to create a process and control it, that's a whooooooooole nother story.
Last edited by tjpanda; 10-12-2007 at 12:16 AM. Reason: Fixed "...\firefox.exe" to "...\\firefox.exe"
Whilst system() is the most portable (although not very portable), it is also the least safe.
http://faq.cprogramming.com/cgi-bin/...&id=1043284392
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I didn't get an error, but I also didn't get any effect from the shell execute(); command.
Can you post the code you used the ShellExecute with?
>I also read elsewere on this forum that system(); isn't a good command to use.
system() is a perfectly good function to use. It's bad when it's misused (for example, using it to call things like "pause" when you can simply use getchar() ).
>To my knowledge, again which may be wrong, system() echos as if you went to start->run->cmd and you typed the text in.
It's been awhile since I used Windows, but I'm pretty sure that typing a Win32 program at the prompt will open it the way it's supposed to execute, but then again, I could be wrong. I know this works on Mac and Linux.
Code:ShellExecute(NULL, "open", "1.exe", NULL, NULL, NULL);
You should change "1.exe" to the path of 1.exe. For example, if 1.exe resided in C:\ you would need to use:
Code:ShellExecute(NULL, "open", "C:\\1.exe", NULL, NULL, NULL);
The program is still not opening and I get the following errorCode:ShellExecute(NULL, "open", "C:\\Dev-Cpp\\me\\1.exe", NULL, NULL, NULL);
196
C:\Dev-Cpp\Me\dos.cpp
[Warning] passing NULL used for non-pointer converting 6 of `HINSTANCE__* ShellExecuteA(HWND__*, const CHAR*, const CHAR*, const CHAR*, const CHAR*, INT)'