Hope you guys can help. Im trying to make an email option for a program im writing. The program is a c++ executable in Linux (bash). I decided to write a simple bash script, and call the script from the program. Problem is, the program asks for the user to enter their email address and I need that address passed to the script for it to email. When i hard code the email address in, of course it works. But that defeats the purpose.
cout <<"Would you like to email this file? (1=Yes 0=No)\n:";
cin>> choice3; //holds value of user input
if(choice3==1)
{
cout << "Please Enter the email address\n:";
cin >> argv[2]; //argv[] is a buffer
string email = argv[2];
cout << email << endl; //testing
system("./email_script.sh");
cout << "Thanks! Your email will be sent shortly.\n";
}
else
cout << "Thank you! No email will be sent." << endl;
//////////////////////////////////////////////////////////
//email script (email_script.sh)
email=argv[2];
mail email < email_temp.out;
When the program executes, it saves to my Linux email box as dead.letter. When I "vi dead.letter", the Send address is argv[2]. So I assume the script isnt getting the "value", instead its getting the variable name as I declared it. Im a Senior Computer Science college student and fairly decent at programming. This Linux environment just confuses things.
cout <<"Would you like to email this file? (1=Yes 0=No)" << endl << ":";
cin>> choice3;
if(choice3==1)
{
string email;
cout << "Please Enter the email address" << endl << ":";
cin >> email; //reads user input
string cmd = "./email_script.sh ";
cmd += email; //concatenates cmd and email
// cout << cmd << endl; //testing
system(cmd.c_str()); //executes email_script.sh, passes email address
cout << "Thanks! Your email will be sent shortly." << endl;
}
else
cout << "Thank you! No email will be sent." << endl;
//////////////////////////////////////////////////////////
//email script (email_script.sh)
email=$1
mail $email < email_temp.out
I originally had the mail command as "mail email < email_temp.out". Also for the bash script to accept the variable being passed, I had to set email = $1, where $1 holds the value of the passed variable. Also, there are no semi-colons in bash. Don't know what i was thinking.
Everything works perfect now. Thanks ALOT for the help.