This is part of the Fake.Core.Process module.

CreateProcess

Module for creating and modifying CreateProcess<'TRes> instances. You can manage:

  • The command (ie file to execute and arguments)
  • The working directory
  • The process environment
  • Stream redirection and pipes
  • Timeout for the process to exit
  • The result and the result transformations (map, mapResult)

More extensions can be found in the CreateProcess Extensions

Example

1: 
2: 
3: 
4: 
Command.RawCommand("file", Arguments.OfArgs ["arg1"; "arg2"])
|> CreateProcess.fromCommand
|> Proc.run
|> ignore
val ignore : value:'T -> unit

Functions and values

Function or valueDescription
addOnExited f c
Signature: f:('?8711 -> int -> '?8712) -> c:CreateProcess<'?8711> -> CreateProcess<'?8712>
Type parameters: '?8711, '?8712

Execute the given function after the process has been exited and the previous result has been calculated.

addOnFinally f c
Signature: f:(unit -> unit) -> c:CreateProcess<'?8677> -> CreateProcess<'?8677>
Type parameters: '?8677

Execute the given function when the process is cleaned up.

addOnSetup f c
Signature: f:(unit -> '?8674) -> c:CreateProcess<'?8675> -> CreateProcess<'?8675>
Type parameters: '?8674, '?8675

Execute the given function before the process is started

addOnStarted f c
Signature: f:(unit -> unit) -> c:CreateProcess<'?8679> -> CreateProcess<'?8679>
Type parameters: '?8679

Execute the given function right after the process is started.

addOnStartedEx f c
Signature: f:(StartedProcessInfo -> unit) -> c:CreateProcess<'?8681> -> CreateProcess<'?8681>
Type parameters: '?8681

Execute the given function right after the process is started. PID for process can be obtained from p parameter (p.Process.Id).

appendSimpleFuncs(...)
Signature: prepareState:(unit -> '?8670) -> onStart:('?8670 -> Process -> unit) -> onResult:(Async<'?8671> -> '?8670 -> Task<RawProcessResult> -> Async<'?8672>) -> onDispose:('?8670 -> unit) -> c:CreateProcess<'?8671> -> CreateProcess<'?8672>
Type parameters: '?8670, '?8671, '?8672

Attaches the given functions to the current CreateProcess instance.

copyRedirectedProcessOutputsToStandardOutputs(...)
Signature: c:CreateProcess<'?8621> -> CreateProcess<'?8621>
Type parameters: '?8621

Copies std-out and std-err into the corresponding System.Console streams (by using interceptStream).

disableTraceCommand(c)
Signature: c:CreateProcess<'?8625> -> CreateProcess<'?8625>
Type parameters: '?8625

Disable the default trace of started processes.

ensureExitCode(r)
Signature: r:CreateProcess<'?8717> -> CreateProcess<'?8717>
Type parameters: '?8717

Makes sure the exit code is 0, otherwise a detailed exception is thrown (showing the command line).

ensureExitCodeWithMessage msg r
Signature: msg:string -> r:CreateProcess<'?8714> -> CreateProcess<'?8714>
Type parameters: '?8714

throws an exception with the given message if exitCode <> 0

fromCommand(command)
Signature: command:Command -> CreateProcess<ProcessResult<unit>>

Create a simple CreateProcess<_> instance from the given command.

Example

1: 
2: 
3: 
4: 
Command.RawCommand("file", Arguments.OfArgs ["arg1"; "arg2"])
|> CreateProcess.fromCommand
|> Proc.run
|> ignore
val ignore : value:'T -> unit
fromRawCommand command args
Signature: command:FilePath -> args:seq<string> -> CreateProcess<ProcessResult<unit>>

Create a CreateProcess from the given file and arguments

Example

1: 
2: 
3: 
CreateProcess.fromRawCommand "cmd" [ "/C";  "echo test" ]
|> Proc.run
|> ignore
val ignore : value:'T -> unit
fromRawCommandLine(...)
Signature: command:FilePath -> windowsCommandLine:string -> CreateProcess<ProcessResult<unit>>

Create a CreateProcess from the given file and arguments

Example

1: 
2: 
3: 
CreateProcess.fromRawCommandLine "cmd" "/C \"echo test\""
|> Proc.run
|> ignore

Using BlackFox.CommandLine

See BlackFox.CommandLine for details

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
open BlackFox.CommandLine

CmdLine.empty
|> CmdLine.append "build"
|> CmdLine.appendIf noRestore "--no-restore"
|> CmdLine.appendPrefixIfSome "--framework" framework
|> CmdLine.appendPrefixf "--configuration" "%A" configuration
|> CmdLine.toString
|> CreateProcess.fromRawCommandLine "dotnet.exe"
|> Proc.run
|> ignore
val ignore : value:'T -> unit
fromRawWindowsCommandLine(...)
Signature: command:FilePath -> windowsCommandLine:string -> CreateProcess<ProcessResult<unit>>
Attributes:
[<Obsolete("Use fromRawCommandLine instead.")>]
OBSOLETE

Use fromRawCommandLine instead.

Create a CreateProcess from the given file and arguments

getEnvironmentMap(c)
Signature: c:CreateProcess<'?8687> -> EnvMap
Type parameters: '?8687

Retrieve the current environment map.

interceptStream target s
Signature: target:Stream -> s:StreamSpecification -> StreamSpecification

intercept the given StreamSpecification and writes the intercepted data into target. Throws if the stream is not redirected (ie is Inherit).

map f c
Signature: f:('?8697 -> '?8698) -> c:CreateProcess<'?8697> -> CreateProcess<'?8698>
Type parameters: '?8697, '?8698

Map the current result to a new type.

mapFilePath f c
Signature: f:(FilePath -> FilePath) -> c:CreateProcess<'?8631> -> CreateProcess<'?8631>
Type parameters: '?8631

Map the file-path according to the given function.

mapResult f c
Signature: f:('a -> 'b) -> c:CreateProcess<ProcessResult<'a>> -> CreateProcess<ProcessResult<'b>>
Type parameters: 'a, 'b

Map only the result object and leave the exit code in the result type.

ofStartInfo(p)
Signature: p:ProcessStartInfo -> CreateProcess<ProcessResult<unit>>

Create a CreateProcess from the given ProcessStartInfo

redirectOutput(c)
Signature: c:CreateProcess<'a> -> CreateProcess<ProcessResult<ProcessOutput>>
Type parameters: 'a

Starts redirecting the output streams and collects all data at the end.

redirectOutputIfNotRedirected(c)
Signature: c:CreateProcess<'?8705> -> CreateProcess<'?8705>
Type parameters: '?8705

Starts redirecting the output streams if they are not already redirected. Be careful when using this function. Using redirectOutput is the preferred variant

replaceFilePath newFilePath c
Signature: newFilePath:FilePath -> c:CreateProcess<'?8629> -> CreateProcess<'?8629>
Type parameters: '?8629

Replace the file-path

setEnvironmentVariable envKey envVar c
Signature: envKey:string -> envVar:string -> c:CreateProcess<'?8689> -> CreateProcess<'?8689>
Type parameters: '?8689

Set the given environment variable.

warnOnExitCode msg r
Signature: msg:string -> r:CreateProcess<'?8719> -> CreateProcess<'?8719>
Type parameters: '?8719

LikeensureExitCode but only triggers a warning instead of failing.

withCommand command c
Signature: command:Command -> c:CreateProcess<'?8627> -> CreateProcess<'?8627>
Type parameters: '?8627

Set the command to the given one.

withEnvironment env c
Signature: env:(string * string) list -> c:CreateProcess<'?8683> -> CreateProcess<'?8683>
Type parameters: '?8683

Sets the given environment variables

withEnvironmentMap env c
Signature: env:EnvMap -> c:CreateProcess<'?8685> -> CreateProcess<'?8685>
Type parameters: '?8685

Sets the given environment map.

withOutputEvents onStdOut onStdErr c
Signature: onStdOut:(string -> unit) -> onStdErr:(string -> unit) -> c:CreateProcess<'a> -> CreateProcess<'a>
Type parameters: 'a

Calls the given functions whenever a new output-line is received.

withOutputEventsNotNull(...)
Signature: onStdOut:(string -> unit) -> onStdErr:(string -> unit) -> c:CreateProcess<'?8709> -> CreateProcess<'?8709>
Type parameters: '?8709

Like withOutputEvents but skips null objects.

withStandardError stdErr c
Signature: stdErr:StreamSpecification -> c:CreateProcess<'?8693> -> CreateProcess<'?8693>
Type parameters: '?8693

Set the standard error stream.

withStandardInput stdIn c
Signature: stdIn:StreamSpecification -> c:CreateProcess<'?8695> -> CreateProcess<'?8695>
Type parameters: '?8695

Set the standard input stream.

withStandardOutput stdOut c
Signature: stdOut:StreamSpecification -> c:CreateProcess<'?8691> -> CreateProcess<'?8691>
Type parameters: '?8691

Set the standard output stream.

withTimeout timeout c
Signature: timeout:TimeSpan -> c:CreateProcess<'a> -> CreateProcess<'a>
Type parameters: 'a

Set the given timeout, kills the process after the specified timespan

withWorkingDirectory workDir c
Signature: workDir:string -> c:CreateProcess<'?8623> -> CreateProcess<'?8623>
Type parameters: '?8623

Set the working directory of the new process.