C
CodeGrommet
I'm testing out the system() command. I coded the following. How can
I output the results into the given output file? Your help will be
appreciated.
/* system example : DIR */
//code based on: http://www.cplusplus.com/reference/clibrary/cstdlib/system.html
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main ()
{
//opening the log file
ofstream myLog;
myLog.open("C:\\unisa\\MyFiles\\Test_bin\\myLog_test.txt");
//executing sytem() command
int i;
cout<<("Checking if processor is available...")<<endl;
if (system(NULL)) puts ("Ok");
else exit (1);
cout<<("Executing command DIR...\n")<<endl;
i=system ("dir"); //executing the DOS system command
cout<<"The value returned was: "<<i<<endl;
//closing the log file
myLog.close();
return 0;
}
I output the results into the given output file? Your help will be
appreciated.
/* system example : DIR */
//code based on: http://www.cplusplus.com/reference/clibrary/cstdlib/system.html
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main ()
{
//opening the log file
ofstream myLog;
myLog.open("C:\\unisa\\MyFiles\\Test_bin\\myLog_test.txt");
//executing sytem() command
int i;
cout<<("Checking if processor is available...")<<endl;
if (system(NULL)) puts ("Ok");
else exit (1);
cout<<("Executing command DIR...\n")<<endl;
i=system ("dir"); //executing the DOS system command
cout<<"The value returned was: "<<i<<endl;
//closing the log file
myLog.close();
return 0;
}