wxcore-0.90.0.3: wxHaskell core

Portability | portable
Stability | provisional
Maintainer | wxhaskell-devel@lists.sourceforge.net
Safe Haskell | None

Graphics.UI.WXCore.Process

Contents

- Process
- Streams
- Blocking IO
- Non-blocking IO

Description

Process and stream wrappers.

Synopsis

- type OnReceive = String -> StreamStatus -> IO ()
- type OnEndProcess = Int -> IO ()
- processExecAsyncTimed :: Window a -> String -> Bool -> OnEndProcess -> OnReceive -> OnReceive -> IO (String -> IO StreamStatus, Process (), Int)
- processExecAsync :: Window a -> String -> Int -> OnEndProcess -> OnReceive -> OnReceive -> IO (String -> IO (), Process (), Int)
- data StreamStatus
  - = StreamOk
  - | StreamEof
  - | StreamReadError
  - | StreamWriteError
- streamBaseStatus :: StreamBase a -> IO StreamStatus
- inputStreamGetContents :: InputStream a -> IO String
- inputStreamGetContentsN :: InputStream a -> Int -> IO String
- inputStreamGetLine :: InputStream a -> Int -> IO String
- inputStreamGetString :: InputStream a -> Int -> IO String
- inputStreamGetChar :: InputStream a -> IO Char
- outputStreamPutString :: OutputStream a -> String -> IO ()
- inputStreamGetLineNoWait :: InputStream a -> Int -> IO String
- inputStreamGetStringNoWait :: InputStream a -> Int -> IO String
- inputStreamGetCharNoWait :: InputStream a -> IO (Maybe Char)
- outputStreamPutStringNoWait :: OutputStream a -> String -> IO Int

# Process

type OnReceive = String -> StreamStatus -> IO ()

Type of input receiver function.

type OnEndProcess = Int -> IO ()

Type of end-of-process event handler. Gets the exitcode as its argument.

processExecAsyncTimed :: Window a -> String -> Bool -> OnEndProcess -> OnReceive -> OnReceive -> IO (String -> IO StreamStatus, Process (), Int)

(`processExecAsyncTimer command processOutputOnEnd onEndProcess onOutput onErrorOutput parent`) starts the `command` asynchronously. The handler `onEndProcess` is called when the process terminates. `onOutput` receives the output from `stdout`, while `onErrorOutput` receives output from `stderr`. If `processOutputOnEnd` is `True`, the remaining output of a terminated process is processed (calling `onOutput`). The call returns a triple (`send,process,pid`): The `send` function is used to send input to the `stdin` pipe of the process. The process object is returned in `process` and the process identifier in `pid`.

Note: The method uses idle event timers to process the output channels. On many platforms this is uch more thrustworthy and robust than the `processExecAsync` that uses threads (which can cause all kinds of portability problems).

processExecAsync :: Window a -> String -> Int -> OnEndProcess -> OnReceive -> OnReceive -> IO (String -> IO (), Process (), Int)

Deprecated: Use processExecAsyncTimed instead (if possible)

deprecated: use `processExecAsyncTimed` instead (if possible). (`processExecAsync command bufferSize onEndProcess onOutput onErrorOutput parent`) starts the `command` asynchronously. The handler `onEndProcess` is called when the process terminates. `onOutput` receives the output from `stdout`, while `onErrorOutput` receives output from `stderr`. The `bufferSize` determines the intermediate buffer used to cache the output from those channels. The calls returns a triple (`send,process,pid`): The `send` function is used to send input to the `stdin` pipe of the process. The process object is returned in `process` and the process identifier in `pid`.

# Streams

data StreamStatus

The status of a stream (see `StreamBase`)

Constructors

StreamOk | No error.
StreamEof | No more input.
StreamReadError | Read error.
StreamWriteError | Write error.

Instances

Eq StreamStatus |
Show StreamStatus |

streamBaseStatus :: StreamBase a -> IO StreamStatus

Return the status of the stream

# Blocking IO

inputStreamGetContents :: InputStream a -> IO String

Get the entire contents of an input stream. The content is returned as a lazy stream (like `hGetContents`).

inputStreamGetContentsN :: InputStream a -> Int -> IO String

Get the entire contents of an input stream. The content is returned as a lazy stream (like `hGetContents`). The contents are returned in lazy batches, whose size is determined by the first parameter.

inputStreamGetLine :: InputStream a -> Int -> IO String

`inputStreamGetLine s n` reads a line of at most `n` characters from the input stream (potentially waiting for input). The function does automatic end-of-line conversion. If the line ends with `\n`, an entire line has been read, otherwise, either the maximum has been reached, or no more input was available.

inputStreamGetString :: InputStream a -> Int -> IO String

The expression (`inputStreamGetString n input`) reads a string of maximally `n` characters from `input`.

inputStreamGetChar :: InputStream a -> IO Char

Read a single character from the input. (equals `inputStreamGetC`)

outputStreamPutString :: OutputStream a -> String -> IO ()

Write a string to an output stream, potentially blocking until all output has been written.

# Non-blocking IO

inputStreamGetLineNoWait :: InputStream a -> Int -> IO String

`inputStreamGetLineNoWait stream n` reads a line of at most `n` characters from the input stream in a non-blocking way. The function does automatic end-of-line conversion. If the line ends with `\n`, an entire line has been read, otherwise, either the maximum has been reached, or no more input was available.

inputStreamGetStringNoWait :: InputStream a -> Int -> IO String

`inputStreamGetStringNoWait stream n` reads a line of at most `n` characters from the input stream in a non-blocking way.

inputStreamGetCharNoWait :: InputStream a -> IO (Maybe Char)

Read a single character from the input, returning `Nothing` if no input was available (using `inputStreamCanRead`).

outputStreamPutStringNoWait :: OutputStream a -> String -> IO Int

Write a string to an output stream, returning the number of bytes actually written.