Re: Running one program from another
- Posted by ghaberek (admin) Jan 29, 2014
- 1895 views
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 public procedure start( sequence file_name, sequence arguments = {} ) -- start a process with optional arguments sequence command if equal( lower(file_name), lower(filename(file_name)) ) then file_name = search_path( file_name ) end if if not sequence_array( arguments ) then arguments = {arguments} end if ifdef WINDOWS then sequence ComSpec = getenv( "ComSpec" ) -- use ComSpec (cmd.exe) 'start' command to launch the process command = build_commandline( {ComSpec, "/c", "start", file_name} & arguments ) elsedef -- use the background operator '&' to launch the process command = build_commandline( {file_name} & arguments & {"&"} ) end ifdef system_exec( command ) end procedure
-- example include start.e sequence cmdline = command_line() start( "notepad.exe", cmdline[2] )
-Greg