| command$ - file, folder or web address to open, or a program to run followed by its arguments |
|
Opens a file, folder or web address, or runs a program with arguments. ExecFile hands the name to Windows the same way double-clicking it in Explorer would: an .exe is launched, a .txt opens in the default text editor, a folder opens in Explorer, and a web address such as http://... or mailto:... opens in the default browser or mail program. Classic game uses are a "visit our website" button or opening a readme. To give a program arguments, write them after its name, as you would on a command line: ExecFile "notepad.exe readme.txt". The program is the text up to the first space, and the rest goes to the program as written, without the spaces around it. If the program's path has spaces, wrap it in quote characters, e.g. ExecFile Chr$(34)+"C:\My Tools\editor.exe"+Chr$(34)+" level1.txt". A path that names an existing file or folder in full opens even when it has spaces and no quotes. Your program does not wait - the other application runs alongside it and ExecFile returns immediately. Relative paths are resolved against the current directory, like the other file commands. On Linux, programs in the current directory or on PATH accept quoted arguments, including web addresses as arguments. Files, folders and addresses such as https: or mailto: open through xdg-open and the configured default application. Linux arguments are passed literally, without shell expansion. On a Mac, ExecFile opens files, folders and web addresses but cannot give a program arguments. In a web build it opens only http, https and mailto addresses. See also: SystemProperty, CommandLine, CurrentDir. |
; ExecFile Example
; ----------------
; ExecFile launches another program (or opens a document with its
; associated program) via the Windows shell.
Print "This example can launch the Windows Notepad."
Print ""
Print "Press and hold Y to launch Notepad, or any other key to skip"
WaitKey
; WaitKey returns as the key goes down, so the chosen key is still held
If KeyDown(21) Then
; Launch Notepad - wrap paths in Chr$(34) quotes if they have spaces
ExecFile "notepad.exe"
Print "Launched notepad.exe"
Else
Print "Skipped launching Notepad."
EndIf
Print ""
Print "Press any key to close the example"
WaitKey
End