Re: Running one program from another

new topic     » goto parent     » topic index » view thread      » older message » newer message
eukat said...
ghaberek said...

This is what I use...

-- start.e 
 
include std/cmdline.e 
include std/filesys.e 
include std/search.e 
include std/sequence.e 
include std/text.e 
include std/types.e 
 
public function search_path( sequence file_name ) 
-- search the PATH environment variable for a file 
     
    sequence PATH = getenv( "PATH" ) 
     
    if atom( PATH ) then 
        PATH = current_dir() 
    end if 
     
    sequence paths = split( PATH, PATHSEP, 1 ) 
     
    for i = 1 to length( paths ) do 
         
        sequence path = paths[i] 
         
        if not search:ends( SLASH, path ) then 
            path &= SLASH 
        end if 
         
        path &= file_name 
         
        if file_exists( path ) then 
            return path 
        end if 
         
    end for 
     
    return "" 
end function 
 
<snip> 
 
 

You could just use dir(file_name). No dir = it does not exist.

In place of the call to file_exists() ? Agreed. In fact, at least in some cases, file_exists() is implemented using this very method.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu