I have a troubles with the following. Let's say, I have a two programs, one is "input.c" and second is "output.c". Output is a simple one and looks like this (I will paste only the most important passage).
outputbin.c
//
char buffer[512];
strncpy(buffer, argv[1], sizeof(buffer));
printf("Your output is: %s\n", buffer);
//
And this is the main passage from my input.c:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(int argc, char *argv[])
{
pid_t pid;
char *charchar = "\x41";
int status;
char *outputbin;
int i, j, iterations;
if(argc < 2)
{
fprintf(stderr, "Usage: %s <iterations> <outputbin>\n", argv[0]);
exit(0);
}
iterations = atoi(argv[1]);
outputbin = argv[2];
pid = fork();
if(pid != 0)
{
waitpid(-1, &status, 0);
}
if(pid == 0)
{
for(i=0; i < iterations; ++i)
{
for(j = 0; j <= i; ++j)
{
printf("%s", charchar);
//execl(outputbin, outputbin, charchar, NULL);
}
printf("\n");
}
}
return 0;
}
When I compile this program using gcc and do this (without argv[2]): ./input 10 I get this:
A
AA
AAA
AAAA
AAAAA
AAAAAA
AAAAAAA
AAAAAAAA
AAAAAAAAA
AAAAAAAAAA
It's okay, but only till I remove this piece of code - "printf("%s", input);" and uncomment "execl", so:
for(j = 0; j <= i; ++j)
{
execl(output, output, input, NULL);
}
And run: ./a.out 10 ./outputbin
I get only this - Your output is: A
Only first char and that's all. How to let is execute whole "half pyramid" of strings line by line? No matter what I tried, everything end with the same result.