forEach method

void forEach(
  1. LineAction stdout, {
  2. LineAction stderr = _noOpAction,
  3. bool runInShell = false,
  4. bool extensionSearch = true,
})

forEach runs the contents of this String as a command line application.

DCli performs Glob expansion on command arguments. See run for details.

Output from the command can be captured by providing handlers for stdout and stderr.

// Capture output to stdout and print it.
'grep alabama regions.txt'.forEach((line) => print(line));

// capture output to stdout and stderr and print them.
'grep alabama regions.txt'.forEach((line) => print(line)
    , stderr: (line) => print(line));

Any environment variables you set via env'xxx' will be passed to the new process.

If you need to pass an argument to your application that contains spaces then use nested quotes: e.g.

'wc "fred nurk.text"'.run;

See run if you don't care about capturing output toList to capture stdout and stderr as a String list. toParagraph to concatenating the return lines into a single string. start - if you need to run a detached sub process. firstLine - returns just the first line written to stdout or stderr. lastLine - returns just the last line written to stdout or stderr. parser - returns a parser with the captured output ready to be interpreted as one of several file types.

Implementation

void forEach(
  core.LineAction stdout, {
  core.LineAction stderr = _noOpAction,
  bool runInShell = false,
  bool extensionSearch = true,
}) =>
    cmd.start(
      this,
      progress: Progress(stdout, stderr: stderr),
      runInShell: runInShell,
      extensionSearch: extensionSearch,
    );