Pabbisetty.henr@xerox.com (Nagesh Pabbisetty) (02/18/89)
Folks, I am currently developing a tool that transfers files between file servers and workstations. The tool reads commands from a file. Provision is made to specify the time at which this tool is to start tranfering files. However, sybntax-checking of the command-file should be done at the current time, It is possible that the user of this tool has different login names and passwords on different file servers. I want the program to accept the various login names and passwords at the current time. Then, when the actual file transfer is to take place, I want the program to login to the 2 file servers involved in the transfer (validate credentials using "servlogin") and continue with the transfer operation. In order to test if fork-exec-pipe combination would help me in the process, I developed a prototype, excerpts of which are given below: ---------------------------------- # include <stdio.h> # define R 0 # define W 1 main() { int fork(), p[2], q[2] ; FILE *writeptr, *readptr; char buffer[200]; if (pipe(p) == -1) perror("pipe(p) failed\n"); if (pipe(q) == -1) perror("pipe(q) failed\n"); switch(fork()) { case 0: /* child process */ close(p[W]); close(R); dup(p[R]); close(p[R]); close(q[R]); close(W); dup(q[W]); close(q[W]); execlp("/export/swap/opt/sun3/servlogin","servlogin",0); perror("exec failed\n"); exit (1); case -1: /* unsuccesful fork */ perror("fork failed\n"); exit (1); default: /* parent process */ close(p[R]); close(q[W]); writeptr = fdopen(p[W],"w"); readptr = fdopen(q[R],"r"); /* this obviously doesn't work! */ fprintf(writeptr,"Pabbisetty\n"); fflush(writeptr); fprintf(writeptr,"hastalavista\n"); fflush(writeptr); . . . fclose(writeptr); } } ---------------------------------- As is obvious from this simple program, I have set up bi-directional pipes between the parent and the child process. From the parent, I am trying to pipe the user-name and password to the login process. However, this doesn't work. I get the login prompt to the terminal!! How can I get the login process to accept login-name and password from the parent process and not expect it from the terminal? Could anyone out there suggest a correct way to do this? Any help in this regard is appreciated!!! Thanks.... Nagesh 716-427-1827 / 5458