所以我用dart语言编写了一种编程语言。因此,我不知道如何在不运行dart编译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_work\darting\something.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)我怎样才能修复或者至少让这件事再起作用?
发布于 2022-06-22 15:33:50
出现此错误是因为生成进程的环境不包括您通常的PATH环境变量,因此它不知道在哪里查找dart命令。
您可以通过将runInShell设置为true来修复此问题。这样,进程将像在shell中使用相同的环境变量被调用一样运行。
Process.runSync(
'dart compile exe ${args[0].replaceAll(".idk", ".dart")}',
[],
runInShell: true,
)
.stdout.toString();https://stackoverflow.com/questions/72690926
复制相似问题