runExternalCommand method
dynamic
runExternalCommand(
- dynamic command,
- dynamic path
Helps to create temporary script to run on the system
Implementation
runExternalCommand(command, path) async {
return 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']);
outputFile = SystemUtils.pathSeparator(
[presentWorkingDirectory, 'assets', 'output', '$fileName.txt']);
debugPrint((projectDirectory).toString());
final commandString = _commandStringGenerator(command, path, outputFile);
final data = File(filePath + fileScript);
final sink = data.openWrite();
sink.write(commandString);
return sink.flush().then((_) {
sink.close();
return Process.run(fileScript, [],
workingDirectory: filePath, runInShell: true)
.then((result) {
data.delete();
// Toast.show("Command Run Complete", message: command);
// fixme: refactor
// Toast.notify("Command finished: $command",
// outputFile: outputFile!, message: "Output saved in: $outputFile");
});
});
});
// return "cd $filePath; ./$fileName";
}