Is there a way for you to code program like on a modern computer.. where C is typically in the console to open an application.. just to make an example everyone will know.. like get C to open I.E. or something like that??
Is there a way for you to code program like on a modern computer.. where C is typically in the console to open an application.. just to make an example everyone will know.. like get C to open I.E. or something like that??
Yes, have a look at the FAQ here.
It's quite natural that this HAS TO BE POSSIBLE, because the shell/command prompt is actually written in C - so it has to be able to run another program. The same applies for whatever application is responsible for displaying your desktop, start-menu or whatever is your graphical user-interface - it's all written in C (or C++).
--
Mats
If you're on Windows, have a look at CreateProcess or ShellExecute
I know a good example
I had written something similar to what you are describing to make my desktop less cluttered.
There is a way that I know of :
You have to know the name of it's process. That is in Windows by the way.Code:system("start iexplore.exe");
It can run anything in the system32 folder, and anything in the same folder as your executable.
Last edited by sea_4_ever; 08-25-2007 at 09:05 PM. Reason: Misspellings, and bad grammar
Wrong. It can run any program contained in the paths specified in its PATH environment variable.It can run anything in the system32 folder, and anything in the same folder as your executable.
Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction
Thanks for correcting me Happy Reaper,
I learn something new every day...
I never meant the standard. In windows, calling system('cmd') will work for any command located in one of the paths specified in the PATH environment variable.
Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction
It might just be me, but we are a bit off of the original purpose of this thread.
Regarding robatino's post :
You can start a few things, but I think they have to be .exe
hmm...
There was a comand for that, (or was that in cygwin?) I think basically, you have to open things that are not .exe with a program.
example :
notepad "C:\textfiles\text.txt"
OR
iexplore "C:\html\webpage.html"
But I am not sure.
That's not what I'm talking about - "notepad" and "iexplore" are executables, the arguments you give them ("C:\textfiles\text.txt" or "C:\html\webpage.html") aren't. You should be able to run the executables by giving their full path (I don't know offhand what those are) without relying in it being in PATH.
...Run the executables..?
you mean like :
'C:\WINDOWS\system32\notepad.exe'
I don't think I am understanding what you are saying.
"run the executables by giving their full path without relying in it being in PATH"
What?
This is very definitely in the YMMV territory, but VC6 at least does what you suspect might happen from looking at the code.Code:#include <stdio.h> #include <stdlib.h> int main ( ) { putenv("COMSPEC=C:\\windows\\notepad.exe"); system("cmd"); return 0; }
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.