2

Is there any way to make the script:

diff <(echo 'hello') <(echo 'hello-2')

work, as currently it fails with error in Dart when run using Process.run or Process.start:

syntax error near unexpected token `('

I tried to drill down on it and found out that since process substitution is not available when running the script through Process.run or Process.start, hence it's failing. So, is there any way to make it work?

I found out that we need to use set +o posix to make process substitution available if it's not, but I don't know how to do it in Dart.

Aakash
  • 2,239
  • 15
  • 23

1 Answers1

0

According to the documentation and common expectations, the shell will be /bin/sh; and so, you can't use Bash features like process substitutions.

You can always force it by running Bash explicitly:

Process.run("bash", ["-c", "diff <(echo 'hello') <(echo 'hello-2')"])

You could add set +o posix; to the beginning of the argument to bash -c (the argument can be an arbitrarily complex string with multiple commands) but of course, it's not necessary here, and actually a red herring in this context.

Here's an example of a slightly more complex command which uses the Bash-only "C-style" for loop syntax.

Process.run("bash", ["-c", "for ((i=0; i<=255; i++)); do ping -c 3 10.9.8.$i || break; done; echo 'finished'"])

... though generally speaking, it's probably better to keep your subprocesses as simple as possible, and write any necessary plumbing in the host language.

Perhaps see also Difference between sh and bash

tripleee
  • 175,061
  • 34
  • 275
  • 318