factor/extra/io/launcher/launcher-docs.factor

180 lines
11 KiB
Factor
Raw Normal View History

! Copyright (C) 2007, 2008 Slava Pestov.
2007-11-16 21:07:18 -05:00
! See http://factorcode.org/license.txt for BSD license.
2008-02-21 20:12:55 -05:00
USING: help.markup help.syntax quotations kernel io math
calendar ;
2007-11-16 21:07:18 -05:00
IN: io.launcher
2008-03-06 21:44:52 -05:00
ARTICLE: "io.launcher.command" "Specifying a command"
"The " { $snippet "command" } " slot of a " { $link process } " can contain either a string or a sequence of strings. In the first case, the string is processed in an operating system-specific manner. In the second case, the first element is a program name and the remaining elements are passed to the program as command-line arguments." ;
2007-11-16 21:07:18 -05:00
2008-03-06 21:44:52 -05:00
ARTICLE: "io.launcher.detached" "Running processes in the background"
"By default, " { $link run-process } " waits for the process to complete. To run a process without waiting for it to finish, set the " { $snippet "detached" } " slot of a " { $link process } ", or use the following word:"
{ $subsection run-detached } ;
2007-11-16 21:07:18 -05:00
2008-03-06 21:44:52 -05:00
ARTICLE: "io.launcher.environment" "Setting environment variables"
"The " { $snippet "environment" } " slot of a " { $link process } " contains an association mapping environment variable names to values. The interpretation of environment variables is operating system-specific."
2007-11-16 21:07:18 -05:00
$nl
2008-03-06 21:44:52 -05:00
"The " { $snippet "environment-mode" } " slot controls how the environment of the current Factor instance is composed with the value of the " { $snippet "environment" } " slot:"
{ $subsection +prepend-environment+ }
{ $subsection +replace-environment+ }
{ $subsection +append-environment+ }
"The default value is " { $link +append-environment+ } "." ;
ARTICLE: "io.launcher.redirection" "Input/output redirection"
"On all operating systems except for Windows CE, the default input/output/error streams can be redirected."
2007-11-16 21:07:18 -05:00
$nl
2008-03-06 21:44:52 -05:00
"To specify redirection, set the " { $snippet "stdin" } ", " { $snippet "stdout" } " and " { $snippet "stderr" } " slots of a " { $link process } " to one of the following values:"
{ $list
{ { $link f } " - default value; the stream is either inherited from the current process, or is a " { $link <process-stream> } " pipe" }
{ { $link +inherit+ } " - the stream is inherited from the current process, overriding a " { $link <process-stream> } " pipe" }
{ { $link +closed+ } " - the stream is closed; reads will return end of file and writes will fails" }
{ { $link +stdout+ } " - a special value for the " { $snippet "stderr" } " slot only, indicating that the standard output and standard error streams should be merged" }
{ "a path name - the stream is sent to the given file, which must exist for input and is created automatically on output" }
{ "a file stream or a socket - the stream is connected to the given Factor stream, which cannot be used again from within Factor and must be closed after the process has been started" }
} ;
HELP: +closed+
2008-03-06 21:44:52 -05:00
{ $description "Possible value for the " { $snippet "stdin" } ", " { $snippet "stdout" } ", and " { $snippet "stderr" } " slots of a " { $link process } "." } ;
HELP: +inherit+
2008-03-06 21:44:52 -05:00
{ $description "Possible value for the " { $snippet "stdin" } ", " { $snippet "stdout" } ", and " { $snippet "stderr" } " slots of a " { $link process } "." } ;
HELP: +stdout+
{ $description "Possible value for the " { $snippet "stderr" } " slot of a " { $link process } "." } ;
2008-02-05 18:33:36 -05:00
HELP: +prepend-environment+
2008-03-06 21:44:52 -05:00
{ $description "Possible value of " { $snippet "environment-mode" } " slot of a " { $link process } "."
$nl
"If this value is set, the child process environment consists of the value of the " { $snippet "environment" } " slot together with the current environment, with entries from the current environment taking precedence."
2007-11-16 21:07:18 -05:00
$nl
"This is used in situations where you want to spawn a child process with some default environment variables set, but allowing the user to override these defaults by changing the environment before launching Factor." } ;
2008-02-05 18:33:36 -05:00
HELP: +replace-environment+
2008-03-06 21:44:52 -05:00
{ $description "Possible value of " { $snippet "environment-mode" } " slot of a " { $link process } "."
$nl
"The child process environment consists of the value of the " { $snippet "environment" } " slot."
2007-11-16 21:07:18 -05:00
$nl
"This is used in situations where you want full control over a child process environment, perhaps for security or testing." } ;
2008-02-05 18:33:36 -05:00
HELP: +append-environment+
2008-03-06 21:44:52 -05:00
{ $description "Possible value of " { $snippet "environment-mode" } " slot of a " { $link process } "."
$nl
"The child process environment consists of the current environment together with the value of the " { $snippet "environment" } " key, with entries from the " { $snippet "environment" } " key taking precedence."
2007-11-16 21:07:18 -05:00
$nl
"This is used in situations where you want a spawn child process with some overridden environment variables." } ;
2008-03-06 21:44:52 -05:00
ARTICLE: "io.launcher.timeouts" "Process run-time timeouts"
{ $description "The " { $snippet "timeout" } " slot of a " { $link process } " can be set to a " { $link duration } " specifying a maximum running time for the process. If " { $link wait-for-process } " is called and the process does not exit before the duration expires, it will be killed." } ;
2007-11-16 21:07:18 -05:00
HELP: get-environment
2008-03-06 21:44:52 -05:00
{ $values { "process" process } { "env" "an association" } }
{ $description "Combines the current environment with the value of the " { $snippet "environment" } " slot of the " { $link process } " using the " { $snippet "environment-mode" } " slot." } ;
2007-11-16 21:07:18 -05:00
2008-02-15 00:34:20 -05:00
HELP: current-process-handle
{ $values { "handle" "a process handle" } }
{ $description "Returns the handle of the current process." } ;
2007-11-16 21:07:18 -05:00
HELP: run-process*
{ $values { "desc" "a launch descriptor" } { "handle" "a process handle" } }
2007-11-16 21:07:18 -05:00
{ $contract "Launches a process using the launch descriptor." }
{ $notes "User code should call " { $link run-process } " instead." } ;
HELP: run-process
2008-01-31 00:16:20 -05:00
{ $values { "desc" "a launch descriptor" } { "process" process } }
2008-03-06 21:44:52 -05:00
{ $description "Launches a process. The object can either be a string, a sequence of strings or a " { $link process } ". See " { $link "io.launcher.descriptors" } " for details." }
{ $notes "The output value can be passed to " { $link wait-for-process } " to get an exit code." } ;
2007-11-16 21:07:18 -05:00
HELP: run-detached
2008-01-31 00:16:20 -05:00
{ $values { "desc" "a launch descriptor" } { "process" process } }
2008-03-06 21:44:52 -05:00
{ $contract "Launches a process without waiting for it to complete. The object can either be a string, a sequence of strings or a " { $link process } ". See " { $link "io.launcher.descriptors" } " for details." }
2007-11-16 21:07:18 -05:00
{ $notes
2008-03-06 21:44:52 -05:00
"This word is functionally identical to passing a " { $link process } " to " { $link run-process } " having the " { $snippet "detached" } " slot set."
$nl
"The output value can be passed to " { $link wait-for-process } " to get an exit code."
2007-11-16 21:07:18 -05:00
} ;
2008-02-08 22:15:29 -05:00
HELP: process-failed
{ $values { "code" "an exit status" } }
{ $description "Throws a " { $link process-failed } " error." }
{ $error-description "Thrown by " { $link try-process } " if the process exited with a non-zero status code." } ;
HELP: try-process
{ $values { "desc" "a launch descriptor" } }
{ $description "Launches a process and waits for it to complete. If it exits with a non-zero status code, throws a " { $link process-failed } " error." } ;
2008-02-03 15:23:14 -05:00
HELP: kill-process
{ $values { "process" process } }
{ $description "Kills a running process. Does nothing if the process has already exited." } ;
HELP: kill-process*
{ $values { "handle" "a process handle" } }
{ $contract "Kills a running process." }
{ $notes "User code should call " { $link kill-process } " intead." } ;
HELP: process
2008-03-06 21:44:52 -05:00
{ $class-description "A class representing a process. Instances are created by calling " { $link <process> } "." } ;
HELP: <process>
{ $values { "process" process } }
{ $description "Creates a new, empty process. It must be filled in before being passed to " { $link run-process } "." } ;
HELP: process-stream
{ $class-description "A bidirectional stream for interacting with a running process. Instances are created by calling " { $link <process-stream> } ". The " { $link process-stream-process } " slot holds a " { $link process } " instance." } ;
2007-11-16 21:07:18 -05:00
HELP: <process-stream>
2008-01-31 00:16:20 -05:00
{ $values
{ "desc" "a launch descriptor" }
2008-02-21 16:22:49 -05:00
{ "encoding" "an encoding descriptor" }
2008-01-31 00:16:20 -05:00
{ "stream" "a bidirectional stream" } }
2008-03-06 21:44:52 -05:00
{ $description "Launches a process and redirects its input and output via a pair of pipes which may be read and written as a stream of the given encoding." } ;
2007-11-16 21:07:18 -05:00
HELP: with-process-stream
2008-01-31 00:16:20 -05:00
{ $values
{ "desc" "a launch descriptor" }
{ "quot" quotation }
{ "status" "an exit code" } }
{ $description "Calls " { $snippet "quot" } " in a dynamic scope where " { $link stdio } " is rebound to a " { $link process-stream } ". After the quotation returns, waits for the process to end and outputs the exit code." } ;
HELP: wait-for-process
{ $values { "process" process } { "status" integer } }
{ $description "If the process is still running, waits for it to exit, otherwise outputs the exit code immediately. Can be called multiple times on the same process." } ;
2007-11-16 21:07:18 -05:00
2008-02-09 23:28:22 -05:00
ARTICLE: "io.launcher.descriptors" "Launch descriptors"
2008-03-06 21:44:52 -05:00
"Words which launch processes can take either a command line string, a sequence of command line arguments, or a " { $link process } "."
$nl
"Strings and string arrays are wrapped in a new empty " { $link process } " with the " { $snippet "command" } " slot set. This covers basic use-cases where no launch parameters need to be set."
$nl
"A " { $link process } " instance can be created directly and passed to launching words for more control. It must be a fresh instance which has never been spawned before. To spawn a process several times from the same descriptor, " { $link clone } " the descriptor first." ;
ARTICLE: "io.launcher.lifecycle" "The process lifecycle"
"A freshly instantiated " { $link process } " represents a set of launch parameters. Words for launching processes take a fresh process which has never been started before as input, and output a copy as output."
{ $link process-started? }
"The " { $link process } " instance output by launching words contains all original slot values in addition to the " { $snippet "handle" } " slot, which indicates the process is currently running."
{ $link process-running? }
"It is possible to wait for a process to exit:"
{ $link wait-for-process }
"A running process can also be killed:"
{ $link kill-process } ;
ARTICLE: "io.launcher.launch" "Launching processes"
"Launching processes:"
2007-11-16 21:07:18 -05:00
{ $subsection run-process }
2008-02-08 22:15:29 -05:00
{ $subsection try-process }
"Redirecting standard input and output to a pipe:"
{ $subsection <process-stream> }
2008-03-06 21:44:52 -05:00
{ $subsection with-process-stream } ;
ARTICLE: "io.launcher" "Operating system processes"
"The " { $vocab-link "io.launcher" } " vocabulary implements cross-platform process launching."
{ $subsection "io.launcher.descriptors" }
{ $subsection "io.launcher.launch" }
"Advanced topics:"
{ $subsection "io.launcher.lifecycle" }
{ $subsection "io.launcher.command" }
{ $subsection "io.launcher.detached" }
{ $subsection "io.launcher.environment" }
{ $subsection "io.launcher.redirection" }
{ $subsection "io.launcher.timeouts" } ;
2007-11-16 21:07:18 -05:00
ABOUT: "io.launcher"