nyse@nicedel.north.de (Hermann Behrens) (04/30/91)
Hello. I have problems to execute an external protocoll, in this case zmodem. I open the device, let the programm call a mailbox(up to this point no problems), but when i have to execute the sz, i get errors :-( this is my routine to start sz: int zm_upload() { int pid, status; chdir("/somewhere"); if((pid = fork()) == 0) { close(fp); close(0); open("/dev/ttyF00", O_RDONLY | O_NDELAY); close(1); open("/dev/ttyF00", O_WRONLY | O_NDELAY); /* I think, that the bug is in the redirecting of stdin and stdout, but where is the bug?? */ execl("/bin/sh", "sh", "-c", "sz a_file",NULL); } else wait(&status); } int zm_download() { int pid, status; chdir("/somewhere"); if((pid = fork()) == 0) { close(fp); close(0); open("/dev/ttyF00", O_RDONLY | O_NDELAY); close(1); open("/dev/ttyF00", O_RDONLY | O_NDELAY); execl("/bin/sh", "sh", "-c", "rz", NULL); } else wait(&status); } It would be great, if someone could help me ... ciao, Hermann Behrens -- Hermann Behrens|Bremerstr. 323|2870 Delmenhorst|04221/71931(DATA)71932(VOICE)
les@chinet.chi.il.us (Leslie Mikesell) (05/01/91)
In article <1991Apr29.221812.5038@nicedel.north.de> nyse@nicedel.north.de (Hermann Behrens) writes: > if((pid = fork()) == 0) { > close(fp); > close(0); > open("/dev/ttyF00", O_RDONLY | O_NDELAY); > close(1); > open("/dev/ttyF00", O_WRONLY | O_NDELAY); >/* I think, that the bug is in the redirecting of stdin and stdout, >but where is the bug?? */ > execl("/bin/sh", "sh", "-c", "sz a_file",NULL); On the machines I use, leaving O_NDELAY set will cause very strange things to happen when you try to write to a device and reads will complete when no data is present. I'd suggest leaving out the O_NDELAY on the open if you have reason to expect that carrier is already up (but you might want to set an alarm to bail you out just in case). Or, use fcntl() to turn it off after the open before you let another program try to access the line. Les Mikesell les@chinet.chi.il.us