running a external file

This is a discussion on running a external file within the C++ Programming forums, part of the General Programming Boards category; How would i get my prog to run a file in the same dir like a *.bat file and if ...

  1. #1
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    running a external file

    How would i get my prog to run a file in the same dir like a *.bat file and if poss not make it open in a window

  2. #2
    Unregistered
    Guest
    Since you said .bat file I assume you are using windows. Look up the documentation on CreateProcess(). There is a flag you send so it will inherit the current console.

  3. #3
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    why do you assume he's using windows for .bat files? Batch files are for DOS, not windows, even though you can use them to run windows programs.

  4. #4
    Registered User Sekti's Avatar
    Join Date
    Feb 2002
    Posts
    163
    here you go

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    int main()
    {
    cout<<"Running sekti.bat"<<endl;
    system("sekti.bat");
    cout<<"Boom"<<endl;
    return 0;
    }
    system() is what you would use
    +++
    ++
    + Sekti
    ++
    +++

  5. #5
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    i have returned

    i am using wind0ze btw but not all bat commands work?
    summit to do with sharing violation
    i thinks its cus the file has been opened in my prog but do i have to close it then?

  6. #6
    Unregistered
    Guest
    You are using windows, so use create process. Here is an example:

    STARTUPINFO s; /* INPUT PARAMETER */
    PROCESS_INFORMATION p; /* OUTPUT PARAMETER */
    char* filename = "c:\autoexec.bat"; /* FILE TO EXECUTE */

    /* SEARCH DOCS FOR ALL THE THINGS YOU CAN DO WITH A
    STARTUPINFO STRUCTURE */
    s.cb = sizeof(STARTUPINFO);
    s.lpReserved = NULL;
    s.lpDesktop = NULL;
    s.lpTitle = NULL;
    s.cbReserved2 = 0;
    s.lpReserved2 = NULL;
    s.dwFlags = STARTF_USESTDHANDLES;
    s.hStdInput = GetStdHandle (STD_INPUT_HANDLE);
    s.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE);
    s.hStdError = GetStdHandle (STD_OUTPUT_HANDLE);


    // SEARCH DOCS FOR INFO ON ARG OPTIONS TO
    // CREATEPROCESS
    if (!CreateProcess(
    NULL,
    filename,
    NULL,
    NULL,
    FALSE,
    0,
    NULL,
    NULL,
    &s,
    &p ) )
    printf("Couldnt create process1\n");

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 05:27 PM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 04:53 AM
  4. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 04:44 PM
  5. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 05:14 AM

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