| tsamisa@gmail.com 2006-05-30, 1:20 am |
| I'm writing an application that automatically access a webpage and
fills some blanks using lynx. I send char "g" then the url and up to
that point it works fine. My problem is that i can't send the ascii
code (i tried ascii 80,66,25) for arrow dwn in order for lynx to move
to the next i/p field or hyperlink.
Here is the code
#include <stdio.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <string.h>
void writer ( FILE* stream,int sleeptime)
{
sleep(2);
fprintf(stream,"g");
sleep(1);
fprintf(stream,"www.msn.com\n");
sleep(1);
//here it was supposed to move through the screen
fprintf(stream,"%c",25);
fflush (stream);
sleep (sleeptime);
}
int main(int argc,char * argv[])
{
char lynx[400];
int fds[2];
pid_t pidntw;
FILE *stream;
strcpy(lynx,"lynx");
pipe (fds);
pidntw = fork();
if(pidntw == (pid_t) 0)
{
close (fds[1]);
close(0);
dup2 (fds[0],STDIN_FILENO);
execlp(lynx,"lynx","-accept_all_cookies",0);
return(1);
}
else
{
close (fds[0]);
stream = fdopen (fds[1], "w");
if (ferror (stream) || stream==NULL)
printf("ERROR!! 3\n");
writer(stream,10);
fclose(stream);
close (fds[1]);
waitpid(pidntw,NULL,0);
}
return 0;
}
|