Hi, how would I make a program that gets input from a user, sends it to a program with popen(), gets the output, and repeats this until the program ends? I have tried, but I only get part of the output, and when I type "exit", it won't end the program.
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
int main()
{
FILE *fp = popen("cmd.exe", "r+" );
char buff[50];
char command[50];
while (fp != NULL)
{
while ( fgets( buff, sizeof buff, fp ) != NULL )
{
cout << buff;
}
cin.getline(command, sizeof command);
fputs(command, fp);
}
pclose( fp );
getch();
}
From this, I only get "Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp." when it starts, while I should also be getting the "C:\documents and settings\...." after it.