如何在省道文件中编译省道文件

  • 本文关键字:文件 编译省 dart
  • 更新时间 :
  • 英文 :


所以我正在制作一种dart编程语言。所以我不知道如何在没有运行dart compile exe命令的情况下在dart文件中编译dart文件。这是我的代码

import 'dart:io';
void main(List<String> args) async {
String contents = new File(args[0]).readAsStringSync();
// ignore: unused_local_variable
var fileCopy = File(args[0].replaceAll('.idk', '.dart')).writeAsStringSync(contents);
Process.runSync('dart compile exe ${args[0].replaceAll(".idk", ".dart")}',[]).stdout.toString();
Process.runSync('del ${args[0].replaceAll(".idk", ".dart")}', []).stdout.toString();
print("${args[0]} has compiled");
}

我如何在不运行命令的情况下编译dart文件,因为需要人们拥有完整的文件路径。但是现在在尝试编译.idk文件时又出现了另一个问题。

ProcessException: The system cannot find the file specified.
Command: "dart compile exe F:code_workdartingsomething.dart"
#0      _ProcessImpl._runAndWait (dart:io-patch/process_patch.dart:487)
#1      _runNonInteractiveProcessSync (dart:io-patch/process_patch.dart:632)        
#2      Process.runSync (dart:io-patch/process_patch.dart:68)
#3      main (file:///f:/code_work/darting/test.dart:7)
#4      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192)

我怎么能修复或至少使它再次工作?

这个错误的发生是因为生成的进程的环境不包括您通常的PATH环境变量,所以它不知道在哪里查找dart命令。

您可以通过将runInShell设置为true来修复此问题。这样,进程就会像在shell中调用一样运行,使用相同的环境变量。

Process.runSync(
'dart compile exe ${args[0].replaceAll(".idk", ".dart")}', 
[],
runInShell: true,
)
.stdout.toString();

最新更新