Home > OS >  how to run command in Dart correctly?
how to run command in Dart correctly?

Time:02-03

That's my code. I want to use Process.run to open a command to do something, like git clone or flutter build.

import 'dart:io';

void main() async {
  print('build start');
  // var res = await Process.run('git clone xxxx', []);
  var res = await Process.run('flutter build windows --dart-define=RunEnv=dist', []);
  print(res);
  print('build end');
}

But it failed.

Unhandled exception:
ProcessException: 系统找不到指定的文件。

  Command: flutter

Dart Process can't read global command variable like flutter or git? In nodejs is easy to do that. What should I do?

CodePudding user response:

Your syntaxis is not right. All parameters have to supplied as a list of string, rewrite it to:

final ProcessResult res = await Process.run( 'flutter', [ 'build', 'windows', '--dart-define=RunEnv=dist' ], );

[Edit] Link to documentation: https://api.flutter.dev/flutter/dart-io/Process/run.html [/edit]

  • Related