| | |
executing the windows command prompt
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
You can call an external program with the system() function:
But that's probably not what you want since you need the output. In that case, you need to create a pipe either through the Win32 API, or with a compiler extension if supported. For example, on Visual C++ .NET you would use SetCurrentDirectory to change the current working directory to the one you want, then _popen to create a pipe to the DIR program. After that it's just a matter of reading the FILE pointer returned by _popen just like any other stream:
C++ Syntax (Toggle Plain Text)
#include <stdlib.h> system("DIR");
C++ Syntax (Toggle Plain Text)
#include <stdio.h> #include <windows.h> int main(void) { FILE *fp; SetCurrentDirectory("C:\\"); fp = _popen("DIR", "r"); if (fp != NULL) { char buffer[BUFSIZ]; while (fgets(buffer, sizeof buffer, fp) != NULL) fputs(buffer, stdout); } return 0; }
•
•
Join Date: Feb 2005
Posts: 12
Reputation:
Solved Threads: 0
thanks, but the following works good enough
C++ Syntax (Toggle Plain Text)
void listDatFiles() { cout <<endl << "All .dat files in this folder are as followed:" << endl << "-----------------------" <<endl; system("dir *.dat /B /O N"); displayContinue(); }
![]() |
Similar Threads
- Module not found when running in command prompt (Python)
- XP command prompt (Windows NT / 2000 / XP)
- getting around spaces in windows command prompt commands (Windows NT / 2000 / XP)
- Command Prompt (Windows Software)
- Unknown Bootup Command (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: The question about "new"
- Next Thread: Advice on hearing loss simulation using C++
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





