CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 1999
    Location
    CA
    Posts
    188

    Executing DOS batch files from C

    I am attempting to execute DOS batch files from a C++ program. I tried using the CreateProcess() function but I get no results. The function returns without an error, but the batch file doesn't run.

    Any pointers?



  2. #2
    Join Date
    May 1999
    Location
    Miami, Florida
    Posts
    242

    Re: Executing DOS batch files from C

    Hmm.. I use CreateProcess() all the time and I can't conceive of a reason why it wouldn't work for a dos file. Try something simpler like WinExec shown below:

    const char cmdLine[] = "\\windows\\notepad.exe";
    UINT result = WinExec(cmdLine, SW_SHOW);
    if (result < 32)
    {
    // handle error
    }





  3. #3
    Join Date
    May 1999
    Location
    CA
    Posts
    188

    Re: Executing DOS batch files from C

    Alrighty.

    First, thanks for the first reply. I had found a solution, messy as it is, for my conundrum.

    I will try to explain.

    To run a .bat file from a windows program, one must use the cmd.exe command from the windows directory. Pass to cmd.exe the name of the batch file you wish to execute as a parameter.
    Now be careful not to use DETACHED_PROCESS in the creation flags.

    The pain is that it seems you have to change directories to where the batch file lives but use a the full windows path before cmd.exe. (as in C:\WINNT\cmd.exe).

    The result is messy because it pops up a DOS window for the execution of the batch.

    Be sure to restore the current directory when your done.



  4. #4
    Join Date
    Jun 1999
    Posts
    23

    Re: Executing DOS batch files from C

    To Eric

    Try this

    CreateProcess( NULL, Program, NULL, NULL, FALSE, CREATE_SEPARATE_WOW_VDM | NORMAL_PRIORITY_CLASS, NULL, NULL, &StartUpInfo, &ProcessInfo );

    Matthew Cross


  5. #5
    Join Date
    Jun 1999
    Location
    Canada - Québec
    Posts
    273

    Re: Executing DOS batch files from C

    you can try system();
    its very easy to use..


  6. #6
    Join Date
    Jun 1999
    Posts
    315

    Re: Executing DOS batch files from C

    you can mess with the CreateProcess options and prevent it from showing a window

    miked

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured