简体   繁体   中英

How to run shell commands using dart on macOS

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM