System call with multiple variables

Hello,
I'm trying to make a system call using values from external file.
Using mostly C not C++ because using the code on RB PI, with Arduino shield for other parts needed in project.

I can't get system call to work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int setup ()
{
   FILE *fp;
   char buff[255];
   char m1[255];

   fp = fopen("Mail_List.txt", "r");
   fscanf(fp, "%s", buff);
   sprintf(m1,"%s %s %s", "bash ssmpt" , buff , "<mail1.sh");
   printf(m1);
   system(m1);
   printf("\n");
   fclose(fp);
   


}


From the code above, sprintf(m1,"%s %s %s", "bash ssmpt" , buff , "<mail1.sh"); should combine the needed call.
Using printf(m1), just to check if the cobined call is right, and it should be, but when system(m1) is used I'm getting ssmpt error, that file is not found.

Using 2 files for the code. Mail_List.txt contains e-mails in format needed for SSMPT, mail1.sh contains actual message.

Trying to make it like this is for ease of use. If I have to change the mailing list, I can do it easly just changing the Mail_List.txt file, same goes for the actual e-mails that is sent.

SSMPT needs the call system("bash ssmpt mail1@something.com, mail2@something.com <mail.sh")

Till this point I have tryed everything. Did try to push more or less same meaning of code in C++, but that didn't work as well, decited to stick to C in order to code to be written in one language.

Can anyone please help me?
Last edited on
Topic archived. No new replies allowed.