Re: XForms: Problem understanding fl_exe_command

Steve Lamont (spl@szechuan.ucsd.edu)
Tue, 6 Jul 99 07:03:08 PDT

# To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> I do not quite know how fl_exe_command works. The following piece of code
> gives me problems. I am using XForms 0.89 on a Pentium Pro machine running
> Linux 2.0.35.

Methinks that fl_check_command() is broken, at least on the platforms I
could try it on. TC?

Use waitpid(). Here's a workaround:

#include <sys/types.h>
#include <sys/wait.h>

#define NONBLOCK 0
#define BLOCK 1

long pid;
FL_OBJECT *status;

pid=fl_exe_command("mcopy -n a:file", NONBLOCK);
for (;;) {

int cmd_status;

waitpid( pid, &cmd_status, WNOHANG );

fl_addto_browser_chars(status,".");
if ( cmd_status ) {
fl_end_command(pid);
break;
}
sleep(1);
}

You may want to check the return code from waitpid() for errors. You
may also want to call fl_check_forms() in the loop to cause the
browser to properly update.

Even though fl_end_command() duplicates the waitpid(), you should
still call it, since it does other necessary cleanup.

spl
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuhs.mil or see
http://bob.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuhs.mil/mailserv/list-archives/