Re: system/system_exec problem
- Posted by jbrown105 at speedymail.org Jun 17, 2003
- 480 views
On Tue, Jun 17, 2003 at 11:41:26AM -0400, irvm at ellijay.com wrote: > > > Maybe this is a bug - whatever - but it's keeping me from writing > a program I need. > <snip> > #!/home/irv/euphoria/bin/exu > object x > x = system_exec("ls > DIRECTORY",0) > > This works, if it's run from the command line or from an xterm, but > HANGS if run it by clicking on the program's icon. > > Exu eventually times out after about 30 seconds, > but no DIRECTORY file is produced, no ex.err either. > > I've tried 0,1,2 for the last parameter, with the same results. > Using Mandrake 9.1, KDE, Euphoria 2.4 beta > > Irv > Strange. If anything, it sounds like a flaw in the way KDE handles the running of apps from the icon. Try the following program at the bottom of this email, it bypasses the Eu routine and goes straight into glibc ... if this program also hangs, then its not a bug in Eu. jbrown P.S. Are you sure the redirection works in the command line? The docs say that redirection is not possible in system_exec(), but that might only apply to DOS/Win. --hooks and wrappers into libc constant STDLIB = open_dll("") constant PIPE = define_c_func(STDLIB, "pipe", {C_POINTER}, C_INT) constant READ = define_c_func(STDLIB, "read", {C_INT, C_POINTER, C_INT}, C_INT) constant WRITE = define_c_func(STDLIB, "write", {C_INT, C_POINTER, C_INT}, C_INT) constant CLOSE = define_c_func(STDLIB, "close", {C_INT}, C_INT) constant DUP2 = define_c_func(STDLIB, "dup2", {C_INT, C_INT}, C_INT) constant FORK = define_c_func(STDLIB, "fork", {}, C_INT) constant EXECVP = define_c_func(STDLIB, "execvp", {C_POINTER, C_POINTER}, C_INT) constant WAIT4 = define_c_func(STDLIB, "wait4", {C_INT, C_POINTER, C_INT, C_POINTER}, C_INT) constant CREAT = define_c_func(STDLIB, "creat", {C_POINTER, C_INT}, C_INT) constant ERRNO = define_c_var(STDLIB, "errno") global constant os_stdin = 0 global constant os_stdout = 1 global constant os_stderr = 2 global atom os_errno os_errno = 0 global function os_pipe() atom cmd, r, in, out cmd = allocate(8) r = c_func(PIPE,{cmd}) if r = -1 then os_errno = peek4u(ERRNO) return -1 end if in = peek4u(cmd) out = peek4u(cmd+4) free(cmd) return {in, out} end function global function os_read(atom fd, integer bytes) atom buf, r sequence data buf = allocate(bytes) r = c_func(READ, {fd, buf, bytes}) if r = -1 then os_errno = peek4u(ERRNO) return -1 end if if r = 0 then free(buf) return "" end if data = "" for i = 1 to r do data &= peek(buf+i-1) end for return data end function global function os_write(atom fd, sequence str) atom buf, r buf = allocate_string(str) r = c_func(WRITE, {fd, buf, length(str)}) if r = -1 then os_errno = peek4u(ERRNO) return -1 end if return r end function global function os_close(atom fd) atom r r = c_func(CLOSE, {fd}) if r = -1 then os_errno = peek4u(ERRNO) return -1 end if return 0 end function global function os_dup2(atom oldfd, atom newfd) atom r r = c_func(DUP2, {oldfd, newfd}) if r = -1 then os_errno = peek4u(ERRNO) return -1 end if return r end function global function os_fork() atom pid pid = c_func(FORK, {}) if pid = -1 then os_errno = peek4u(ERRNO) return -1 end if return pid end function global function os_execvp(sequence s, sequence v) atom sbuf atom vbuf sequence vbufseq atom r sbuf = allocate_string(s) vbufseq = "" for i = 1 to length(v) do vbufseq &= allocate_string(v[i]) end for vbufseq &= 0 vbuf = allocate(length(vbufseq)*4) poke4(vbuf, vbufseq) r = c_func(EXECVP, {sbuf, vbuf}) -- execvp() should never return os_errno = peek4u(ERRNO) return r end function global function os_creat(sequence s, integer m) atom sbuf atom ret sbuf = allocate_string(s) ret = c_func(CREAT, {sbuf, m}) if ret = -1 then os_errno = peek4u(ERRNO) end if free(sbuf) return ret end function global function os_wait4(integer pid, atom status_p, integer op) --hacked!!! atom ret ret = c_func(WAIT4, {pid, status_p, op, NULL}) return ret end function global function fake_system_exec(sequence command, sequence file) atom pid, fd atom status_p atom t pid = os_fork() if pid = -1 then return -1 elsif pid = 0 then fd = os_creat(file, 448) t = os_dup2(fd, os_stdout) t = os_dup2(fd, os_stderr) if os_execvp(command[1], command) then abort(127) end if else status_p = allocate(4) --4 = sizeof(int) t = os_wait4(pid, status_p, 0) return peek4s(status_p) end if end function --start of test program atom x x = fake_system_exec({"ls"}, "DIRECTORY") ? x -- /"\ ASCII ribbon | http://www.geocities.com/jbrown1050/ \ / campain against | Linux User:190064 X HTML in e-mail and | Linux Machine:84163 /*\ news, and unneeded MIME | http://verify.stanford.edu/evote.html