wwUtils::ExecuteCommandLine

Executes a complete operating system command line with command arguments, using ShellExecute() command line resolution, but lets you express the command as a single command line that is the same as what you'd run from the Terminal. It also executes Application Protocols, URLs, and opens documents based on non-executable extensions.

Executables are searched for along the OS path, so you can use notepad to launch NotePad without specifying a full path.

This function exists to allow for more natural command line syntax, so that you don't have to separate the command line and parameters. Applications that are in your OS path can be resolved without requiring a full path.

Unlike FoxPro's Run command it also works with long paths and paths with spaces in it.

* Path resolution for notepad
ExecuteCommandLine("notepad .\config.fpw")

* Even simpler - resolves path relative to current path
ExecuteCommandLine("code .\")

* Explicit Path and Command Line (all one line!)
lcCommandLine = 
  ["C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.exe"
   "\WebConnectionProjects\wwThreads\wwThreads.sln"]
ExecuteCommandLine(lcCommandLine)

ExecuteCommandLine() also works with standard ShellExecute() 'command resolution' of Application Protocols and file name extensions:

ExecuteCommandLine("https://webconnection.west-wind.com")   && opens browser
ExecuteCommandLine("skype:3212223333")                      && opens skype
ExecuteCommandLine("c:\temp\test.pdf")                      && opens PDF viewer

While these last syntax values work, we'd recommend you use ShellExecute() just to be more obvious about the intent and reserve use of ExecuteCommandLine() for execution of executables.

o.ExecuteCommandLine(lcCommandLine, lcFolder)

Parameters

lcCommandLine
A full command line for an executable or shell executable Application Protocol or file extensioned file.

For EXE command line arguments use a single string parameter and preferably wrap both the executable and all parameters into quotes:

["executable.exe" "parm1" "parm2" "parm3"].

If the executable contains spaces it has to be quoted and parameters should always be quoted with double quotes.

lcFolder
Optional - specify a base folder out of which the application runs. If not specified the folder is set to the current path of your application. This is useful if you pass parameters that require relative paths.

Remarks

  • An EXE path with spaces should have double quotes around the path.
  • Any parametres with spaces also should be quoted with double quotes or single quotes
  • The EXE path can be specified without a path and it will be looked up using the System path.

See also:

Class wwUtils

© West Wind Technologies, 2023 • Updated: 05/18/20
Comment or report problem with topic