SitePoint Sponsor

User Tag List

Results 1 to 1 of 1

Threaded View

  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calling/running dos commands from C program

    Gudday all
    It seems to be a simple task but one that has taxed my obsolete grey matter to the hilt.
    I would like call the dos command string dir /b | findstr /c:".RPT" from a C program and return the value as a variable. This variable is a file name of form *.RPT. I would then like to use this variable to open that file for manipulation. (I am using the dos command as the name of the .RPT file can vary depending upon day and date of creation.)
    Code:
    system("dir /b | findstr /c:\".RPT\" ");
    
     inputFile = fopen("<file name found by system call>", "r"); //fopen("file name","mode i.e r-read");
    The above code sends to the screen the .RPT file name e.g. it finds it quite well. See attachment.
    I originally used system() as noted above but am aware that there are other alternatives viz. fork(), pipe() etc:

    What would be the best alternative to use to get the information back to my C program?

    But how do I prevent it from being echoed to the screen and also have it so that I may use it as I wish?
    Attached Images Attached Images
    Last edited by Tigers!; Jun 24, 2009 at 17:50. Reason: Clarify what I am asking
    ========================
    Carn the Tiges!
    www.petalsandpatches.com


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
  •