How can I read an output from dos console?

Hi,
I am a c++ noob and what I need is to ;
1)open console
2)open a file via dos console
3)when I open it, it will return an output and I need to read it.

I've been searching internet and all I can find is cin and cout commands =)


I managed to open the file I need but cannot read the output from console.

Thanks in advance.
Last edited on
closed account (3qX21hU5)
http://www.cplusplus.com/doc/tutorial/files/

There you go
I know how to write/read a text file, I need to do it via dos console and I dont understand how I can use ifstream for that.
I managed to open file with system command now I just need to read it :)
closed account (3qX21hU5)
I don't think I'm understanding your question right. Could you post some code to help me understand a little better?
I can't post the code right now, Its on my laptop and doesn't have access to internet right now, but I'll try to explain it

1)I have a text file including some data
2)I have an .exe which I have to open via msdos console with text file
(I need to type C:\\myfile.exe data.txt in console)
3) executable file reads the text file and returns me an output(not as a text file unfortunately, it is on console) I need that input.

I managed to open files but i cannot read the input.
My console looks like this

C:\\myfile.exe data.txt
121.456 <== line i need to read
Last edited on
closed account (3qX21hU5)
So let me get this straight cause im still confused. This is probably because I'm still quite new at C++.

1) - You have a text file with 121.456 in it.

2) - You have a executable program that you need to run in the command prompt to read the said text file.

3) - What the .exe read is displayed on the command prompt, you want to write some code to read that number from the command prompt?


Im quite confused here and if someone more experianced can chime in I think they might be of more help. The way I see it is if you want to read something from a text file by using a program you made in C++ why not eliminate the command prompt in general and just read straight from the text file?
I would output the string you need to a file and then read it
C:\\myfile.exe data.txt > out.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

string line;
ifstream inputFile;

main() 
{
inputFile.open ("out.txt");
     if(inputFile.is_open())
     {
          getline(inputFile,line);
          cout << line << endl;     
     }     
     return 0;
}
My console looks like this

C:\\myfile.exe data.txt
121.456 <== line i need to read


It sounds like you need to redirect the output
C:\myfile.exe data.txt > output.txt

http://technet.microsoft.com/en-us/library/bb490982.aspx
Thank you!
That works, 1 last question now
I need to repeat this operation 200+ times and read each output.
Is it possible to keep only the last data in text file and delete previous ones?
Topic archived. No new replies allowed.