How to send print() output directly to a file with Dart Editor?

让人想犯罪 __ 提交于 2019-12-12 17:18:18

问题


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.


回答1:


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:

  1. Manually write to a file as demonstrated above.
  2. Copy the console output from Dart Editor.
  3. 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
    
  4. Modify Dart Editor (it's open source) to add the feature you want.


来源:https://stackoverflow.com/questions/17243065/how-to-send-print-output-directly-to-a-file-with-dart-editor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!