runInExternalShell static method
Implementation
static Future<void> runInExternalShell(final String command,
{final String? path, final bool clear = false}) async {
await getTemporaryDirectory().then((projectDirectory) async {
final fileName = const Uuid().v1().substring(0, 10);
final fileScript = "$fileName.sh";
final presentWorkingDirectory = await SystemUtils.pwd();
debugPrint("PWD: $presentWorkingDirectory");
final filePath = SystemUtils.pathSeparator(
[presentWorkingDirectory, 'assets', 'temp-scripts']);
final String outputFile = SystemUtils.pathSeparator(
[presentWorkingDirectory, 'assets', 'output', '$fileName.txt']);
debugPrint(projectDirectory.toString());
final commandString =
_commandStringGenerator(command, path, outputFile, clear: clear);
final data = File(SystemUtils.pathSeparator([filePath, fileScript]));
final sink = data.openWrite();
sink.write(commandString);
return sink.flush().then((_) {
sink.close();
debugPrint("Running script in $filePath\nScript: \n$fileScript\n");
return Process.run(fileScript, [],
workingDirectory: filePath, runInShell: true)
.then((result) {
data.delete();
// Toast.show("Command Run Complete", message: command);
// Toast.notify("Command finished: $command", outputFile,
// message: "Output saved in: $outputFile");
});
});
});
}