1. Run and Forget in Linux

On my Linux box, I need one program ('A') to start another ('B'). Program 'A'
needs to be able to close regardless of what 'B' does. Do I use system() for
this?

-=ck
"Programming in a state of EUPHORIA."
http://www.cklester.com/euphoria/

new topic     » topic index » view message » categorize

2. Re: Run and Forget in Linux

try this:
system("./B arg1 arg2 arg3 &")

The ampersand should mean that the system call will return
immediately, so A can continue operation.

On 9/30/05, cklester <guest at rapideuphoria.com> wrote:
>
>
> posted by: cklester <cklester at yahoo.com>
>
> On my Linux box, I need one program ('A') to start another ('B'). Program=
 'A'
> needs to be able to close regardless of what 'B' does. Do I use system() =
for
> this?
>
> -=ck
> "Programming in a state of EUPHORIA."
> http://www.cklester.com/euphoria/
>
>
>
>


--
MrTrick
----------

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

3. Re: Run and Forget in Linux

cklester wrote:
> 
> On my Linux box, I need one program ('A') to start another ('B'). Program 'A'
> needs to be able to close regardless of what 'B' does. Do I use system() for
> this?
> 
> -=ck
> "Programming in a state of EUPHORIA."
> <a
> href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a>
> 

 From the Comments in system():
system() will start a new DOS or Linux/FreeBSD shell. 
system() allows you to use command-line redirection of 
         standard input and output in the command string st. 

So if it's using the shell, an ampersand at the end of your command string
should start the new program in the background--which is fine for X programs
since it should still display on the X display of the current environment
or for programs which have no output.

In this example, a.ex counts to 5, starts b.ex and keeps going until b.ex
creates a semaphore file in the /tmp directory.

<b>Program a.ex:</b>
#!/usr/local/euphoria/bin/exu
-- replace above with path to exu (run "which exu")
-- chmod +x a.ex

include misc.e  -- for sleep()

-- Program A: Count to 5 then spawn program B and continue to count until
-- program B creates the file /tmp/stop_counting_A

atom i, go, fn
go = 1
i = 0

-- clear initial loop condition
system("rm /tmp/stop_counting_A", 2) --

-- main loop
while go do
    puts(1, sprintf("%d ", i))
    if i = 5 then
        system("./b.ex &", 2)   -- start b without clearing the screen
                                -- remove the & to see the difference
    end if
    sleep(1)
    i = i + 1

    -- check loop stop condition
    fn = open("/tmp/stop_counting_A", "rb")
    if fn != -1 then
        go = 0                  -- bail out since file exists
    end if
end while
-- end program


<b>Program B:</b>
#!/usr/local/euphoria/bin/exu

-- program B: wait rand(10) seconds before creating /tmp/stop_counting_A

include misc.e  -- for sleep()

atom w, fn

w = rand(10)

for i = 1 to w do
    sleep(1)         -- why not sleep(w)?, don't ask me ;)
end for

fn = open("/tmp/stop_counting_A", "wb")
close(fn)         -- create empty file
-- end program


The only noticeable effect of starting program B is that the cursor briefly
goes to the bottom left of the screen (over a ssh session so probably not
noticeable on a real console).

ags
(lurking and too busy to touch even Euphoria :( )

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

4. Re: Run and Forget in Linux

Thanks for the help, guys! I think I've got it now.

-=ck
"Programming in a state of EUPHORIA."
http://www.cklester.com/euphoria/

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

Search



Quick Links

User menu

Not signed in.

Misc Menu