Invokes the given subprocess like a function, passing in input and returning a CommandResult.
Invokes the given subprocess like a function, passing in input and returning a
CommandResult. You can then call result.exitCode
to see how it exited, or
result.out.bytes
or result.err.string
to access the aggregated stdout and
stderr of the subprocess in a number of convenient ways.
If you want to spawn an interactive subprocess, such as vim
, less
, or a
python
shell, set all of stdin
/stdout
/stderr
to os.Inherit
call
provides a number of parameters that let you configure how the subprocess
is run:
the working directory of the subprocess
any additional environment variables you wish to set in the subprocess
any data you wish to pass to the subprocess's standard input
os.Redirect that lets you configure how the process's output stream is configured.
os.Redirect that lets you configure how the process's error stream is configured.
merges the subprocess's stderr stream into it's stdout
how long to wait for the subprocess to complete
enable this to throw an exception if the subprocess fails with a non-zero exit code
disable this to avoid passing in this parent process's environment variables to the subprocess
The most flexible of the os.proc calls, os.proc.spawn
simply configures
and starts a subprocess, and returns it as a java.lang.Process
for you to
interact with however you like.
Similar to os.proc.call, but instead of aggregating the process's
standard output/error streams for you, you pass in onOut
/onErr
callbacks to
receive the data as it is generated.
Similar to os.proc.call, but instead of aggregating the process's
standard output/error streams for you, you pass in onOut
/onErr
callbacks to
receive the data as it is generated.
Returns the exit code of the subprocess once it terminates
Convenience APIs around java.lang.Process and java.lang.ProcessBuilder:
- os.proc.call provides a convenient wrapper for "function-like" processes that you invoke with some input, whose entire output you need, but otherwise do not have any intricate back-and-forth communication
- os.proc.stream provides a lower level API: rather than providing the output all at once, you pass in callbacks it invokes whenever there is a chunk of output received from the spawned process.
- os.proc(...) provides the lowest level API: an simple Scala API around java.lang.ProcessBuilder, that spawns a normal java.lang.Process for you to deal with. You can then interact with it normally through the standard stdin/stdout/stderr streams, using whatever protocol you want