I read those ch04-tools-editor, get-started and searched on Google, but I didn't find any answers. How to send print() output directly to a file with Dart Editor?
EDIT : I want to send (pipe/redirect stream) the data (what print() return) directly in a file, instead the Dart Editor. I'm looking for a feature of the Dart Editor.
print()
doesn't output to files; it outputs to the console (stdout
in console apps, the browser console in browsers).
The dart:io
library offers plenty of functionality for I/O, including reading and writing files. One example:
import 'dart:io';
void main() {
var out = new File('output.txt').openWrite();
out.write("String written to file.\n");
out.close();
}
Update: As per your updated question, you're looking for a Dart Editor feature that automatically writes console output to a file. To the best of my knowledge, there's no such feature. Your options include:
- Manually write to a file as demonstrated above.
- Copy the console output from Dart Editor.
Run your app from outside Dart Editor. On any UNIX-like system, for example, you can redirect stdout
like this:
dart my-app.dart >output.txt
- Modify Dart Editor (it's open source) to add the feature you want.