call ahk from kotlin

Discuss other programming languages besides AutoHotkey
User avatar
SL5
Posts: 341
Joined: 12 May 2015, 02:10
GitHub: sl5net
Contact:

call ahk from kotlin

10 Oct 2018, 17:53

Code: Select all

fun main(args: Array<String>) {
            var ahkCode = "MsgBox,% \" ${LocalDateTime.now()} (\" A_LineNumber \" \" RegExReplace(A_LineFile,\".*\\\\\") \")\""
            ahkCode = """
            MsgBox,% "hi :) ${LocalDateTime.now()}(" A_LineNumber " " RegExReplace(A_LineFile,".*\\") ")"
                """
            var outputFile = doAhk(ahkCode)
            outputFile?.forEachLine { println(it) }

        }

        fun doAhk(ahkCode: String): File? {
            val ahkDir = "E:\\fre\\private\\HtmlDevelop\\AutoHotKey\\"
            val ahkNameWithoutExtension = "exec-ahk-commandLineParas"
            val ahkName = "${ahkNameWithoutExtension}.ahk"
            val inputFileName = "${ahkName}.input.inc.ahk"
            val outputFileName = "${ahkName}.output.txt"
            val inputFile = File("$ahkDir$inputFileName")
            if (inputFile.exists())
                inputFile.delete()
            Thread.sleep(100)
            val outputFile = File("$ahkDir$outputFileName")
            inputFile.writeText(ahkCode)
            var i = 0
            while (!inputFile.exists() && i++ < 100)
                Thread.sleep(20)
            if (outputFile.exists())
                outputFile.delete()
            val commandLine = "${ahkDir}${ahkName} ${inputFile.absolutePath} ${outputFile.absolutePath}"
            val p = Runtime.getRuntime().exec("cmd /c " + commandLine)
            println(p.toString())


            i = 0
            while (!outputFile.exists() && i++ < 100)
                Thread.sleep(20)
            var fileExists = outputFile.exists()

            if (!fileExists) {
                println("${outputFile.absolutePath} does not exist.")
            } else {
                println("${outputFile.absolutePath} does exist.")
                //                Thread.sleep(100)
//                outputFile.forEachLine { println(it) }
            }
            return outputFile
        }

Return to “Other Programming Languages”

Who is online

Users browsing this forum: No registered users and 1 guest