1. system/system_exec problem

Maybe this is a bug - whatever - but it's keeping me from writing 
a program I need.

In its simplest form:

-- Program 1
#!/home/irv/euphoria/bin/exu
system("ls > DIRECTORY",0)

This works, producing a file named DIRECTORY containing the filenames 
in my current directory, whether it's run from the command line or run by 
clicking on the program's icon.

-- Program 2
#!/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

new topic     » topic index » view message » categorize

2. Re: system/system_exec problem

Hi Irv,

> -- Program 2
> #!/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. 

Doc says "system_exec() doesn't allow the use of command-line
redirection in the command string st".

Regards,
Igor Kachan
kinz at peterlink.ru

new topic     » goto parent     » topic index » view message » categorize

3. Re: system/system_exec problem

Igor Kachan & Irv Mullins wrote:
>>-- Program 2
>>#!/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. 
> 
> Doc says "system_exec() doesn't allow the use of command-line
> redirection in the command string st".

A bit more long-winded, but this technique might work (untested):

#!/home/path/exu
object x

-- create a temporary script to do the redirection
x = open("tempscript", "w")
   puts(x,
     "ls > DIRECTORY" & "\n" & -- command we wish to execute
     "exit $?" & "\n"          -- return the error status
   )
close(x)

-- make it executable
system("chmod 700 tempscript",2)

-- run it; tempscript returns status into x
x = system_exec("tempscript", 0)

-- tidy up
system("rm -f tempscript")

Carl

-- 
[ Carl R White == aka () = The Domain of Cyrek = ]
[ Cyrek the Illogical /\ www.cyreksoft.yorks.com ]

new topic     » goto parent     » topic index » view message » categorize

4. Re: system/system_exec problem

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

new topic     » goto parent     » topic index » view message » categorize

5. Re: system/system_exec problem

On Tuesday 17 June 2003 12:29 pm, Igor wrote:

> Doc says "system_exec() doesn't allow the use of command-line
> redirection in the command string st".

You are correct, that is what the doc say.
However, they lie, because when I run 
 -- Program 2
 #!/home/irv/euphoria/bin/exu
 object x
 x = system_exec("ls > DIRECTORY",0)

from an x-term, or from the command line, it runs just fine, and 
produces the output file 'DIRECTORY', which contains the names of the files as 
produced by ls.

Only when clicking on the program's icon does it hang.

Just to see if redirection could be part of the problem, I tried the 
following: 
 -- Program 3
 #!/home/irv/euphoria/bin/exu
 object x
 x = system_exec("mv FILEA FILEB",0)

This does not use redirection, but it also fails when run from the icon, and 
succeeds when run from an x-term.

Very puzzling. 

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

6. Re: system/system_exec problem

On Tuesday 17 June 2003 12:53 pm, you wrote:
>
> Igor Kachan & Irv Mullins wrote:
> >>-- Program 2
> >>#!/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.
> >
> > Doc says "system_exec() doesn't allow the use of command-line
> > redirection in the command string st".
>
> A bit more long-winded, but this technique might work (untested):
>
> #!/home/path/exu
> object x
>
> -- create a temporary script to do the redirection
> x = open("tempscript", "w")
>    puts(x,
>      "ls > DIRECTORY" & "\n" & -- command we wish to execute
>      "exit $?" & "\n"          -- return the error status
>    )
> close(x)
>
> -- make it executable
> system("chmod 700 tempscript",2)
>
> -- run it; tempscript returns status into x
> x = system_exec("tempscript", 0)
>
> -- tidy up
> system("rm -f tempscript")

Thanks, Carl,  but same results - like Program 2, yours works from the 
command line, but times out when run by clicking the icon.

Unfortunately, the program I have to write really, really needs to run 
by clicking the icon.

All I can figure is that there must be a difference in the way 
system() and system_exex() are implemented, since system()
works just fine no matter how the program is started.

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

7. Re: system/system_exec problem

On Tuesday 17 June 2003 01:09 pm, jbrown wrote:

> 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.

Thanks, I give it a try. I already tried:

#!/usr/bin/perl
system("ls > DIRECTORY");

Which works fine from the icon (or cmd line)

#!/usr/bin/python
import os
os.system("ls > DIRECTORY")

Also works fine from the icon (or cmd line)

> 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.

Yes. It works every time from the command line or from an xterm.
It even works from the icon IF you tell KDE to "run this in a terminal".
But, of course, that pops up an xterm window, with a "press enter" 
message, which is what I am trying to avoid. And after you tell KDE 
to run euphoria executables in a terminal, it pops up an xterm for every 
euphoria GUI progarm, most of which neither need nor want a terminal.

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

8. Re: system/system_exec problem

On Tuesday 17 June 2003 01:09 pm, jbrown wrote:

> 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.

Your program (snipped) ran just fine - whether from the command line or 
from the icon.

I guess it IS a bug in Eu.

Many thanks,
Irv

new topic     » goto parent     » topic index » view message » categorize

9. Re: system/system_exec problem

Irv:

Maybe you have 2 copies of EXU on your system that have
different permissions to run your program depending on
if your using Icon or Command-line. Did you try creating
a new Icon or checked the property on the Icon.

Bernie

new topic     » goto parent     » topic index » view message » categorize

10. Re: system/system_exec problem

On Tue, Jun 17, 2003 at 02:12:06PM -0400, irvm at ellijay.com wrote:
> 
> 
> On Tuesday 17 June 2003 01:09 pm, jbrown wrote:
> 
> > 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.
> 
> Your program (snipped) ran just fine - whether from the command line or 
> from the icon.
> 
> I guess it IS a bug in Eu.

Since from another post it was determined that system_exec() fails no matter
what when called from an icon, but it works fine when called from an icon
WITH an xterm, perhaps system_exec() is causing some terminal IO to occur.

In 2.3 the use of system() caused ncurses to attempt to initialize a terminal,
which (in a daemon program I was writing) failed, causing much frustration
and motivated me to create the basicio library.

Rob said he fixed that in 2.4, but perhaps he forgot to update system_exec()?

> 
> Many thanks,
> Irv
> 

No problem,
jbrown

-- 
 /"\  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

new topic     » goto parent     » topic index » view message » categorize

11. Re: system/system_exec problem

On Tue, Jun 17, 2003 at 02:00:56PM -0400, irvm at ellijay.com wrote:
> 
> 
> On Tuesday 17 June 2003 01:09 pm, jbrown wrote:
> 
> > 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.
> 
> Thanks, I give it a try. I already tried:
> 
> #!/usr/bin/perl
> system("ls > DIRECTORY");
> 
> Which works fine from the icon (or cmd line)
> 
> #!/usr/bin/python
> import os
> os.system("ls > DIRECTORY")
> 
> Also works fine from the icon (or cmd line)

Ah, I did it the hard way.

glibc provides a C system() function, but I decided to emulate it myself
via execvp() and fork().

Maybe its libc's system() thats failing? But if the perl and python programs
work, and Eu's system() routine does as well, then that would seem very
unlikely...

> 
> > 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.
> 
> Yes. It works every time from the command line or from an xterm.
> It even works from the icon IF you tell KDE to "run this in a terminal".
> But, of course, that pops up an xterm window, with a "press enter" 
> message, which is what I am trying to avoid. And after you tell KDE 
> to run euphoria executables in a terminal, it pops up an xterm for every 
> euphoria GUI progarm, most of which neither need nor want a terminal.

Ah, well I ran over the man page for system(), and I found out that it is
a cross between Eu's system() and system_exec()....the libc system() sends
the string to /bin/sh (POSIX version of command.com) and lets the shell
do the dirty work, which includes running shell scripts (Unix version of
batch files), redirection, and in theory even commands builtin to the shell.
It will also return the exit code of the command it was given, or 127 if there
was an error.

Perhaps the docs should be updated for Linux/FreeBSD?

> 
> Regards,
> Irv
> 

jbrown

-- 
 /"\  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

new topic     » goto parent     » topic index » view message » categorize

12. Re: system/system_exec problem

On Tuesday 17 June 2003 03:52 pm,  Bernie wrote:

> Maybe you have 2 copies of EXU on your system that have
> different permissions to run your program depending on
> if your using Icon or Command-line. Did you try creating
> a new Icon or checked the property on the Icon.

Good thought. I checked, there's only one copy of exu. 
Also, as a double check, I tried a program which I know 
runs ok, and just added the lines:

object x

x = system_exec("cp file1 file2",0)

and the program hangs up. file1 is never copied - unless the program 
is run from the command line, in which case it is copied correctly.

That eliminates the possibility that redirection is the cause of the problem.
I think system_exec is broken, because the identical call in perl, python,
and ruby works properly.

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

13. Re: system/system_exec problem

On Tue, 17 Jun 2003 11:41:26 -0400, irvm at ellijay.com wrote:

>system("ls > DIRECTORY",0)
Can't help you directly on that, but I have a question:
is there any documentation [on what will/will not work]?

Just recently I tried system("open","mailto:"&stuff&stuff) off the
back of something I found on the mailing list archive. It worked a
treat, filling out both the subject and the body (couldn't find a way
to embed newlines in the body, but...)

However, it makes me ask - what is easily possible that I am assuming
is a rack load of work?

Just on the offchance, I opened a dos box and typed "open"; and as
expected "bad command or filename". Where is "open" and everything
else (callable via system()) documented, what do they do?

Pete

new topic     » goto parent     » topic index » view message » categorize

14. Re: system/system_exec problem

On Tuesday 17 June 2003 06:50 pm, you wrote:
>
>
> Hi Irv,
>
> Have experimented, try this
>
> #!/home/irv/euphoria/bin/exu
> integer x
> x = system_exec("ls > DIRECTORY&",0)
>
> Next, use kde's explorer, drag the icon to the desktop, and select
> link here
>
> Works for me

Sorry, no luck. The only thing that _does_ work is to replace system_exec() 
with a call to glibc's system. What version of Linux are you running? That 
may make a difference. (Mandrake 9.1 here)

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

15. Re: system/system_exec problem

jbrown105 at speedymail.org wrote:
> Since from another post it was determined that system_exec() fails no matter
> what when called from an icon, but it works fine when called from an icon
> WITH an xterm, perhaps system_exec() is causing some terminal IO to occur.
> 
> In 2.3 the use of system() caused ncurses to attempt to initialize a terminal,
> which (in a daemon program I was writing) failed, causing much frustration
> and motivated me to create the basicio library.
> 
> Rob said he fixed that in 2.4, but perhaps he forgot to update system_exec()?

Thanks for pointing that out.
I'll make the same change to system_exec()
that I made to system(), so it won't try to
initialize ncurses.

Also, on Linux/FreeBSD, system_exec() calls the
C system() routine, so I/O redirection is possible,
but redirection in system_exec doesn't work on DOS/Windows.
I'll add a note to the docs.

Thanks,
    Rob Craig
    Rapid Deployment Software
    http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

16. Re: system/system_exec problem

On Wednesday 18 June 2003 10:35 am, Chris wrote:
>
>
> Hi Irv
>
> Just tried that little program of yours on two other computers.
>
> 1. SuSE 7.1, Eu2.3, kde2.01, lots of ram and ghz. Works fine, does what
> its supposed to, no hangs.

> 2. SuSE 8.1, Eu2.3, kde3, even more ram and ghz. As above works fine,
> but icon changes to a little cog ('I'm doing something') for 10-15 secs.
> No extra processes seen, and no effect on rest of machine.

> perhaps whats happening is that when Eu finishes, it asks you to hit
> enter, but if there is nowhere to get enter from, it just sits and
> waits, until Linux kills it (all by itself!)

Yes - I think that has something to do with KDE3, it keeps the little taskbar 
icon spinning for a few seconds, even though the program has ended. This is 
true of perl, python, and ruby scripts, as well as euphoria. And it happens 
with xkill, as well. Perhaps any program which doesn't use a "window" causes 
this. It's not really a problem worth worrying about. 

The "not running" part does bother me. I guess I need to go back to an earlier 
version (Mandrake 8.1?) and see if system_exec() works there.

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

17. Re: system/system_exec problem

On Tue, Jun 17, 2003 at 11:43:32PM -0400, Robert Craig wrote:
<snip>
> Thanks for pointing that out.
> I'll make the same change to system_exec()
> that I made to system(), so it won't try to
> initialize ncurses.

It would also be nice if, upon failure to initialize ncurses, an ex.err
would be left instead of just nothing...is this possible? (I'm not too
familar with ncurses.)

That way, at least I'll have an error message and file name+line number
to work with, when I try to do a puts(1, "Hello World!") and ncurses
fails to initalize.

<snip>
> 
> Thanks,
>    Rob Craig
>    Rapid Deployment Software
>    http://www.RapidEuphoria.com
> 

jbrown

-- 
 /"\  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

new topic     » goto parent     » topic index » view message » categorize

18. Re: system/system_exec problem

jbrown105 at speedymail.org wrote:
> It would also be nice if, upon failure to initialize ncurses, an ex.err
> would be left instead of just nothing...is this possible? (I'm not too
> familar with ncurses.)

I'm not sure if it's possible either,
but I'll keep it in mind.

Regards,
    Rob Craig
    Rapid Deployment Software
    http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu