如何在Dart中运行`dir`?

时间:2012-11-07 08:51:36

标签: dart

如何从Dart VM运行dir命令?当我尝试将它与Process类一起使用时,我会得到“未处理的异常”。

1 个答案:

答案 0 :(得分:5)

感谢SørenGjesse的回答,原来是posted this to the Dart mailing list

您不能只在Windows上运行dir,因为它不是独立的可执行文件,而是构建到cmd.exe。以下代码将运行dir并打印结果:

import 'dart:io';

void main() {
    Process.run('cmd', ['/c', 'dir']).then((ProcessResult results) {
      print(results.stdout);
    });
}

有关流程的更多信息,另请参阅Dart IO library

相关问题