I have a program that reads and executes commands from user.
To test it well i was planning to write several commands in a text file and them send those commands one by one to the program.
i've tried :
Code:
main(int argc, char *argv[]){
char line[100];
FILE * fp;
sleep(10);
fp = fopen("script.txt", "r");
if (fp == NULL){
perror("No file");
}else{
while(fgets(line, 100, fp)!=NULL){
usleep((atoi(argv[1]))*1000);
fprintf(stdin,"%s", line);
}
fclose(fp);
}
printf("End\n");
}
there is also a delay between each command to allow time for it's completion.
Is this possible?to write to the stdin?
i make it sleep for 10 seconds so i can run it in the backgound (&), and them run the main program in the same window, but nothing happens.
It just prints out the End after the time as elapsed...