How to run shell commands using dart on macOS

1,671

This may not be useful to you since you're using Flutter, but to answer the question that is in the title (for anyone stumbling upon this writing a non-Flutter app) you should take a look at the dart:io library and its run method:

https://api.dart.dev/stable/2.10.5/dart-io/Process/run.html

Starts a process and runs it non-interactively to completion. The process run is executable with the specified arguments.

Share:
1,671
empt
Author by

empt

Updated on December 21, 2022

Comments

  • empt
    empt over 1 year

    I used Dart process to make shell commands on macOS. I used Flutter to make the macOS app. Now I want to run shell commands from the app.

    Command for running app

    /Users/lihongjun/shell/libs/zipalign -v 4 "/Users/lihongjun/Downloads/app-release.apk" "/Users/lihongjun/Documents/test/tempApk/app_aligned.apk" , 
    

    Error:

     sh: /Users/Shared/shell/libs/zipalign: Operation not permitted
    

    I have searched a lot but I can't resolve this, like process_runner, shell, system plug.

    If I execute shell on mac's Terminal it works well.

    bool rsult = System.invoke('/Users/Shared/shell/libs/zipalign -v 4');
    print('result:$rsult');
    ProcessCmd cmd = ProcessCmd('java', ['-version'],runInShell: false,);
    runCmd(cmd).then((value) {
      print(value.stdout.toString());
    });
    

    Now I want to use the same in Dart code to make the shell commands.

    How can I do this? Thanks!