operator | method

Pipe operator |(
  1. String rhs
)

The classic bash style pipe operator. Allows you to chain multiple processes by piping the output of the left hand process to the input of the right hand process.

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

The following command calls:

  • tail on syslog
  • we pipe the result to head
  • head returns the top 5 lines
  • we pipe the 5 lines to tail
  • tail returns the last 2 of those 5 line
  • We are then back in dart world with the forEach where we print the 2 lines.
'tail /var/log/syslog' | 'head -n 5' | 'tail -n 2'.forEach((line) => print(line));

Implementation

Pipe operator |(String rhs) {
  final rhsRunnable = RunnableProcess.fromCommandLine(rhs)
    ..start(waitForStart: false);

  final lhsRunnable = RunnableProcess.fromCommandLine(this)
    ..start(waitForStart: false);

  return Pipe(lhsRunnable, rhsRunnable);
}