Dynamically parses, compiles and runs source code.
This function is exported by the KS module.
Process := RunScript(Code , CallbackOrAsync, Name := "*", Executable)
Type: String
The source code to compile and execute.
If this is a function object, it is called with the ProcessInfo after the script exits. Any other non-zero, non-unset value starts the run asynchronously without a callback. If omitted or zero, execution is synchronous.
The script name. The default "*" indicates that source is supplied through standard input rather than loaded from a file.
An executable path used to run the compiled assembly. If omitted, the current executable is used.
Type: ProcessInfo
Returns an object which encapsulates the child process and its I/O. Compilation and assembly data are cached, making repeated calls faster than manually starting processes and writing source to standard input.
The object returned by RunScript encapsulates the child process and its redirected I/O. This object has the following methods and properties:
Process.HasExited: Returns 1 if the process has exited and 0 while it is still running.
Process.ExitCode: Returns the process exit code. This is meaningful only once the process has exited.
Process.ExitTime: Returns the time the process exited, in YYYYMMDDHH24MISS form.
Process.StdOut: Returns the process's standard output as a File object, for reading.
Process.StdErr: Returns the process's standard error as a File object, for reading.
Process.StdIn: Returns the process's standard input as a File object, for writing.
Process.Kill(): Terminates the process.
Process.Close(): Closes the redirected streams and releases the process's resources. It does not terminate a running process; use Kill for that.
The three stream properties are created on first access and are the same object on every subsequent access, so a partially consumed stream keeps its position.
#Import "Ks" { RunScript }
Process := RunScript('FileAppend "hello``n", "*"')
MsgBox Process.StdOut