I want to transfer some parameters from one program to another.
For example, here are two programs. a.c compiled as a
#include <stdio.h>
int main() {
char a[10];
scanf("%s", a);
printf("%s\n", a);
return 0;
}
and e.c compiled as e:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int main() {
char *input = "here it is";
execl("./a", "a", "a", NULL);
return 0;
}
Actually, I would like to transfer the parameter “a” from the e.c to a.c so that once I execute the program “e”, it will print out
a
a
However, I find out that excel cannot pass the parameters to the specified program.
If I cannot modify the program a.c, how can I execute this program using another program using standard input?
If you can’t modify
a.c, then you’ll need to write the data to some file, then reset stdin to read from that file:The
unlinksystem call makes sure the file disappears whenais done with it.Note: you might be able to use a pipe instead of a file, because the message is so small that it will fit inside a pipe’s buffer. That’s not a reliable solution for larger messages, though — if you want to use a pipe, you need to
fork.