-
Notifications
You must be signed in to change notification settings - Fork 22
Executing external programs
You can execute external programs by calling the exec function from within a target.
The first argument is the path to the executable and the second is a string containing any command line options, eg:
target openNotepad:
exec("notepad.exe", "")
target openSomeFileUsingNotepad:
exec("notepad.exe", "path\to\somefile.txt")In reality, opening notepad from a build script isn’t really desirable. This is far more useful if you want to run a command line application such as a unit test framework runner or a database migration tool.
By default, Phantom will fail the build if the program executed returns a non-zero exit code. You can change this behaviour by specifying exit codes should be ignored:
target default:
exec("someprogram.exe", "", { 'IgnoreNonZeroExitCode': true })You can also specify a different working directory by passing the WorkingDir option in the arguments hash:
target default:
exec("someprogram.exe", "", { 'IgnoreNonZeroExitCode': true, 'WorkingDir': "path\to\somedir" })If you omit the second parameter when calling exec then rather than starting a new process directly, the command will be piped through the Windows command shell (cmd.exe). This can be useful if you need to execute native commands such as ‘xcopy’.
This can for instance be used to build external .boo files like the following:
target compile:
exec("tools\\Phantom\\Phantom.exe", "", { 'IgnoreNonZeroExitCode': true, 'WorkingDir': "src\\Core" })