Results 1 to 7 of 7

Thread: runing cmd from C

  1. #1
    Join Date
    Oct 2005
    Location
    Saffron Walden
    Beans
    116
    Distro
    Ubuntu 12.04 Precise Pangolin

    runing cmd from C

    hi there guys how would you run a external program in C lets take the windows cmd cos all windows machines sud have tht!!!

    any ideas??

  2. #2
    Join Date
    Nov 2005
    Beans
    22
    Distro
    Ubuntu Breezy 5.10

    Re: runing cmd from C

    What do u mean? Do you mean sending direct commands to the OS using C?

    system(); should work, such as in windows system("dir"); would send the command dir to cmd and return the results. for linux it would be system("ls"); etc.

    I hope this is what your asking, if not, sorry for the waste of time.

  3. #3
    Join Date
    Oct 2005
    Location
    Saffron Walden
    Beans
    116
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: runing cmd from C

    i was more thinking of getting C to open another program, i wasnt to clear on what i ment there sorry

  4. #4
    Join Date
    Nov 2005
    Beans
    22
    Distro
    Ubuntu Breezy 5.10

    Re: runing cmd from C

    im not sure if there is another function in C to do this, but system should be able to work. It must also be said im not the most competant C coder, havn't programmed in it in a long time.

    However, lets say the other program you want to run is in the directory
    "C:\rockfreak\anotherprogram.exe"

    then to run that in a C program would be system("C:\rockfreak\anotherprogram.exe");

    i..think.. give it a try.

  5. #5
    Join Date
    Jan 2005
    Beans
    346

    Re: runing cmd from C

    when did this become a windows forum lol ...


    you'll need to use fork() and excevp()

    this thread should help you get what you need: http://www.ubuntuforums.org/showthre...highlight=fork

  6. #6
    Join Date
    Mar 2005
    Beans
    947
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: runing cmd from C

    system() works almost everywhere (it's ANSI). It's not as sophisticated as fork()/exec(), but you probably don't need it to be.

    popen() is also nice.

  7. #7
    Join Date
    Aug 2005
    Location
    crewe, uk
    Beans
    325
    Distro
    Ubuntu 6.06

    Re: runing cmd from C

    http://www.ubuntuforums.org/showthread.php?t=95533 has a nice simple version of howto do it, there are quite a few ways to skin a cat

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •