Hi guys, maybe I am overworking myself, I think its something simple. I need to record the output of a CMD command to a file.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Function prototypes
void RecordOutput();
int main()
{
char educode[100];
char CommandOutput[128];
printf("Welcome to the network software check software!\n");
printf("\nPlease type your license code!");
printf("\nEducator Code: ");
gets(educode);
if(strcmp(educode, "5678") == 0 )
{
system("ping abv.bg -t");
RecordOutput();
}
else
{
printf("\nSorry, thats not a valid Educator Code.");
}
return 0;
}
void RecordOutput()
{
printf("Debug: Recording started\n");
char CommandOutput[128];
char *f1 = "C://Users//internalhdd//Desktop//RecordingOutput.txt";
FILE *inFile; //Declare inFile
char Byte;
/*int n;*/
/******USER INPUT BLOCK*******/
gets(CommandOutput);
/*int i=0;*/
/******FILE OPEN BLOCK********/
inFile = fopen(f1,"w");
/*****MAIN PROGRAM BLOCK******/
if(inFile == NULL) /* check if the input file is empty */
{
printf("Error: Can't Open inFile\n");
}
else
{
printf("File Opened, Recording\n");
/* recording cycle */
while(1)
{
printf("."); /* loading symbol */
/* if the current byte is not the end of the command's output */
if(Byte!=EOF)
{ /* Byte = function get char from "inFile" */
Byte = fgetc (CommandOutput);
// printf("%d",Byte); /* the new byte from the command output */
/* we put the new byte in the file */
fputc(Byte, inFile);
}
/* if the command is over */
else
{
printf("End of the recording\n");
}
return 1;
}
}
}