CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2008
    Posts
    373

    [RESOLVED] Run Dos Command

    Hi All

    I try to run dos command through mfc vc++.I know run dos command through .bat file.But my question is

    Can i run dos command directly from code?

    Please help me

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Run Dos Command

    Yes, you can. Just use CreateProcess.
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: Run Dos Command

    Directly from code without the DOS black window ?

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Run Dos Command

    Quote Originally Posted by hypheni View Post
    Directly from code without the DOS black window ?
    With ot without the "the DOS black window" will depend on the parameters passed in the CreateProcess. See the documentation in MSDN.
    Victor Nijegorodov

  5. #5
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: Run Dos Command

    CreateProcess is for executing a module, so for dos command run it must have the cmd.exe path as its argument.

    Instead why dont use old system(). Its much more easier if one wants to execute dos command.

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Run Dos Command

    Quote Originally Posted by hypheni View Post
    CreateProcess is for executing a module, so for dos command run it must have the cmd.exe path as its argument.

    Instead why dont use old system(). Its much more easier if one wants to execute dos command.
    A little terminology correction:

    DOS was short for MS-DOS, a 16-bit operating system most popular in the 1980's and early 90's. You also had PC-DOS, DR-DOS, and other variants.

    There is no DOS any more in modern 32/64 bit Windows OS. What you see there is a 32-bit console window.

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: Run Dos Command

    Yes. this I know.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Run Dos Command

    Quote Originally Posted by hypheni View Post
    CreateProcess is for executing a module, so for dos command run it must have the cmd.exe path as its argument.

    Instead why dont use old system(). Its much more easier if one wants to execute dos command.
    No, you don't need the cmd.exe path at all. The OS already know it.
    Victor Nijegorodov

  9. #9
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: Run Dos Command

    So if I want to execute this DOS command what will be the CreateProcess params.

    systeminfo > c:\check.txt

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

  11. #11
    Join Date
    Aug 2008
    Posts
    373

    Re: Run Dos Command

    Thanks for all of you.
    Code:
    CreateProcess
    Problem solved

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