tekartik / process_run.dart

Process run helper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can there be a `runSync` command in this package?

therealsujitk opened this issue · comments

Dart has a Process.runSync() command which works the same way as Process.run() but synchronously. Can you add a process_run.runSync() command that would work the same way as process_run.run() but synchronously? It would also be nice if Shell had this method.

Good idea. Indeed it ends up being fairly easy to implement. It has some slight differences with the async versions as it won't have any stdin or onProcess parameter.

Just published in 0.14.1

Running the script in synchronous mode

runSync and runExecutableArgumentsSync are available since 0.14.1 in the global space and in the Shell class.
They are synchronous version of run and runExecutableArguments respectively with some limitations.

The synchronous mode is useful for testing. It is not recommended for production use as
it is a synchronous call and will block until the child process terminates.

var shell = Shell();
// This is a synchronous call and will block until the child process terminates.
var results = shell.runSync('echo "Hello world"');
var result = results.first;
print('output: "${result.outText.trim()}" exitCode: ${result.exitCode}');
// should display: output: "Hello world" exitCode: 0

Warning:

  • You cannot feed any stdin to the child process.
  • You cannot kill a synchronous child process.
  • Available since 0.14.1
  • Recommended for testing only, it is a synchronous call and will block until the child process terminates.

Works perfectly! Thanks!!

@alextekartik One minor thing, I think the docs need to be updated. The example uses run instead of runSync.

Ah yes thanks @therealsujitk . Fixed in 0.14.1+3