Results 1 to 1 of 1
Jun 23, 2009, 23:52 #1
- Join Date
- Jun 2006
- 0 Post(s)
- 0 Thread(s)
Calling/running dos commands from C program
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.)
system("dir /b | findstr /c:\".RPT\" "); inputFile = fopen("<file name found by system call>", "r"); //fopen("file name","mode i.e r-read");
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?
Last edited by Tigers!; Jun 24, 2009 at 17:50. Reason: Clarify what I am asking========================
Carn the Tiges!