call ahk from kotlin

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: call ahk from kotlin

call ahk from kotlin

Post by SL5 » 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
        }

Top