1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-09-27 12:57:41 +00:00

Support BAT files for the -r options

This commit is contained in:
Karol Stasiak 2020-07-31 13:26:44 +02:00
parent ed55e2f081
commit bce48e8e4a
2 changed files with 13 additions and 2 deletions

View File

@ -66,7 +66,10 @@ Unlike `-I`, this does not replace the default include directory and allows usin
* `-t <platform>` Target platform. It is loaded from an `.ini` file found in any of the include directories. See also [this document](target-platforms.md).
* `-r <program>` Run given program after successful compilation. Useful for automatically launching emulators without any external scripting.
* `-r <program>` Run given program after successful compilation.
Useful for automatically launching emulators without any external scripting.
The program is run with the working directory set to its own directory,
and it's passed the full path to the output file as its argument.
* `-R <param>` Adds a parameter to the command line of the program run with `-r`. All `-R` options are added in order, before the output file name.

View File

@ -167,8 +167,16 @@ object Main {
}
errorReporting.debug(s"Total time: ${Math.round((System.nanoTime() - startTime)/1e6)} ms")
c.runFileName.foreach{ program =>
if (!new File(program).exists()) {
errorReporting.error(s"Program $program does not exist")
}
val outputAbsolutePath = Paths.get(defaultPrgOutput).toAbsolutePath.toString
val cmdline = program +: c.runParams :+ outputAbsolutePath
val isBatch = File.separatorChar == '\\' && program.toLowerCase(Locale.ROOT).endsWith(".bat")
val cmdline = if (isBatch) {
List("cmd", "/c", program) ++ c.runParams :+ outputAbsolutePath
} else {
program +: c.runParams :+ outputAbsolutePath
}
errorReporting.debug(s"Running: ${cmdline.mkString(" ")}")
new ProcessBuilder(cmdline.toArray: _*).directory(new File(program).getParentFile).start()
}