Odd question.. but cna you get C to run an app?

This is a discussion on Odd question.. but cna you get C to run an app? within the C Programming forums, part of the General Programming Boards category; Is there a way for you to code program like on a modern computer.. where C is typically in the ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Location
    Texas
    Posts
    103

    Odd question.. but cna you get C to run an app?

    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??

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    If you're on Windows, have a look at CreateProcess or ShellExecute

  4. #4
    Registered User
    Join Date
    Aug 2007
    Location
    Barbados
    Posts
    31
    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 :
    Code:
    system("start iexplore.exe");
    You have to know the name of it's process. That is in Windows by the way.
    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

  5. #5
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    It can run anything in the system32 folder, and anything in the same folder as your executable.
    Wrong. It can run any program contained in the paths specified in its 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

  6. #6
    Registered User
    Join Date
    Aug 2007
    Location
    Barbados
    Posts
    31
    Thanks for correcting me Happy Reaper,
    I learn something new every day...

  7. #7
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,249
    Quote Originally Posted by Happy_Reaper View Post
    Wrong. It can run any program contained in the paths specified in its PATH environment variable.
    I wasn't aware that the C standard dictates any such thing. The system() function simply invokes the program exactly as specified by calling an appropriate "shell."

  8. #8
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    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

  9. #9
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,249
    Quote Originally Posted by Happy_Reaper View Post
    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.
    What I was getting at, though, is that the REASON that works is because system() invokes a "shell" -- it's this shell which looks through the PATH, not system() itself.

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Quote Originally Posted by Happy_Reaper View Post
    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.
    I'm not familiar with Windows, but can't you run ANY command by specifying the full path of the executable (i.e., C:\foo\bar\cmd.exe)?

  11. #11
    Registered User
    Join Date
    Aug 2007
    Location
    Barbados
    Posts
    31
    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.

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    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.

  13. #13
    Registered User
    Join Date
    Aug 2007
    Location
    Barbados
    Posts
    31
    ...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?

  14. #14
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    int main ( ) {
        putenv("COMSPEC=C:\\windows\\notepad.exe");
        system("cmd");
        return 0;
    }
    This is very definitely in the YMMV territory, but VC6 at least does what you suspect might happen from looking at the code.
    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 support http://www.ukip.org/ as the first necessary step to a free Europe.

  15. #15
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Quote Originally Posted by sea_4_ever View Post
    ...Run the executables..?
    you mean like :
    'C:\WINDOWS\system32\notepad.exe'
    Yes, exactly. If you moved notepad.exe into C:\foo\bar, where C:\foo\bar is not in PATH, you should still be able to run it with the command "C:\foo\bar\notepad.exe" (assuming Windows has this much in common with Unix/Linux, which I think it does).

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MFC Dialog App Screen Refresh Question
    By Scotth10 in forum Windows Programming
    Replies: 2
    Last Post: 10-18-2002, 02:07 PM
  2. GUI App Question ??
    By aumfc in forum Windows Programming
    Replies: 9
    Last Post: 10-17-2002, 02:56 AM
  3. newbie question about using windows app in Dev C++
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2002, 10:50 PM
  4. what does this warningmean???
    By kreyes in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 06:53 AM
  5. onKeyDown(), question in dlg based app
    By codewarrior in forum Windows Programming
    Replies: 0
    Last Post: 10-24-2001, 05:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21