Execute a file lazarus / 8-Other ---------------------------------------------------------------------- Bart · 2006-01-18 16:54 Hi, In Delphi I used to be able to execute a file using shellexecute. This had the advantage that i could run any file that has a file association in Windows. For example: Code: [Select]ShellExecute(Application.Handle, nil,     PChar('http://www.google.com'), PChar(''),     PChar( ''), SW_SHOWNORMAL); would open google.com in the default browser. I use this feature to implement a "Open file in external browser" to open local hmtl files in the default browser from within my htmleditor program. TProcess.Execute or ExecuteProcess however require me to supply the executable itself as a parameter (in this case 'e:\programma's\firefox\firefox.exe'), wich of course is gonna be different on different computers. Can this (executing a non-executable file via its associated program) be done in Lazarus?? I searched the FAQ end the forums, but did not find it. I could implement a ShellExecute() to achieve this (it's just an external Window call), but that would of course _NOT_ be OS independant. I would like to port this app to Linux sometime ... I know this "feature" is available on linux GUI's too, so there must be a OS independant way of implementing it. I hope I made myself clear? Bart ---------------------------------------------------------------------- Anonymous · 2006-01-18 22:25 It depends what  desktop environment you are using. In KDE you can execute the kfmclient command. http://developer.kde.org/documentation/other/kfmclient.html ---------------------------------------------------------------------- mikiwoz · 2006-01-18 22:33 ...but it won't be OS-independent. you will have to use IFDEFs, like: Code: [Select]{$IFDEF linux} [linux code here] // -> in this code you will also have to check, whether it's being run [linux code here] // under KDE or GNOME (or anything else), and act accordingly. {$ENDIF} {$IFDEF win32} [windows code here] {$ENDIF} Cheers mike ---------------------------------------------------------------------- Bart · 2006-01-19 08:56 Quote from: "mikiwoz"...but it won't be OS-independent. you will have to use IFDEFs OK, gonna worry about Linux when I get there then ... First I will implement the ShellExecute and see if it runs ... Bart ---------------------------------------------------------------------- Phil · 2006-01-20 21:06 Quote from: "Bart" In Delphi I used to be able to execute a file using shellexecute. This had the advantage that i could run any file that has a file association in Windows. My own testing seemed to indicate that TProcess doesn't work very well either. ShellExecute works fine with FPC on Windows since it's just a Win API call. For Unix, have you tried the Shell function in the Unix unit? It works fine with Mac OS X. See rtl.pdf for details. However, I don't believe Linux has a standard way of associating files with specific programs the way Windows and OS X do - you'll have to specify the app's name as well as the file it should open. I suppose if your browser is somewhere on the path, Shell will launch it okay without you specifying the complete path to it. Don't forget support for Mac using the OS X Open command:   Shell('Open filename.html'); This opens the file with the program associated with it. You can also start apps with Open without worrying about where they're located:   Shell('Open -a "Microsoft Word"'); If Word is installed in some normal place (for example, in the Applications folder), Open will find it and start it. It doesn't have to be on a path. ---------------------------------------------------------------------- Hansaplast · 2007-06-17 00:24 Would it be an idea to put this in a component? The advantage would be that Windows developers (like me) who have no clue (yet) about these details for Mac and Linux, would not have to figure this out. I realize we cannot cover just about everything, but some basics like; - open URL - open specific application ? For example; I'd like to include Linux and Mac specifics right away, but can't get Phil's "Shell('Open filename.html'); " to go ... (which unit should I include?) ---------------------------------------------------------------------- Phil · 2007-06-17 01:39 Quote from: "Hansaplast"For example; I'd like to include Linux and Mac specifics right away, but can't get Phil's "Shell('Open filename.html'); " to go ... (which unit should I include?) Not sure what "to do" means. If it won't compile, make sure you're using the unix unit since that's where Shell is for Linux and OS X. If it won't open the file, make sure you're passing the complete path for the file. Open isn't a miracle worker or mind reader. Thanks. -Phil ---------------------------------------------------------------------- Hansaplast · 2007-06-17 01:42 Hi Phil, big "duh!" on my end Sorry! ---------------------------------------------------------------------- rajivsoft · 2011-04-12 08:40 Quote from: Phil on January 20, 2006, 10:06:53 pm[...] You can also start apps with Open without worrying about where they're located:   Shell('Open -a "Microsoft Word"'); If Word is installed in some normal place (for example, in the Applications folder), Open will find it and start it. It doesn't have to be on a path. Hi, I'm trying to open NeoOffice from my application but i noticed that it produce a 2-3 seconds freez, confirmed by loglike investigation: [12/04/2011-10.27.26.153]: ExtractFileExt [12/04/2011-10.27.26.153]: if ExtractFileExt [12/04/2011-10.27.26.153]: Open -a "NeoOffice" [12/04/2011-10.27.28.880]: End of EndFileReceive and this is the code executed after [12/04/2011-10.27.26.153]: Open -a "NeoOffice" Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpSystem('Open -a "NeoOffice" "' + FReceiverDirPath + PathDelim + FileName + '"');Is there a way to get rid of this 2-3 seconds lag? ---------------------------------------------------------------------- marcov · 2011-04-12 09:14 Quote from: rajivsoft on April 12, 2011, 10:40:02 am Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpSystem('Open -a "NeoOffice" "' + FReceiverDirPath + PathDelim + FileName + '"');Is there a way to get rid of this 2-3 seconds lag? It's probably the lag for starting the shell and open.   Try to execute it with the path to neooffice instead of using open and see if it speeds up.