The only standard method is the system function:
#include <cstdlib>
#include <iostream>
int main ( int argc, char *argv[] )
{
if ( argc < 2 ) {
std::cerr<<"Too few arguments"<<std::endl;
return EXIT_FAILURE;
}
// Be ultra-anal
if ( std::system ( 0 ) == 0 ) {
std::cerr<<"No command processor available"<<std::endl;
return EXIT_FAILURE;
}
return std::system ( argv[1] );
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s = "mybatchfile ";
string input;
cout<<"Parameters: ";
getline ( cin, input );
system ( ( s + input ).c_str() );
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>parameters = (workStation, printShare);
This doesn't work like you think it does. The comma operator in C++ will evaluate each part, then return the last item. So that line of code is equivalent to tis:
workStation; // Do nothing
parameters = printShare;
If you want to add the two strings together and assign them to parameters, do just that:
parameters = workStation + ' ' + printShare;
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Don't resurrect old threads!
How about beginning with real basic stuff like being able to tell the time, and read intro threads.
Then in a few years we can move on to the hard stuff like batch files.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953