0

i'm trying to run one of .kt files that i have for my side project and I suddenly wanted run my *.kt file that has

fun main(args: Array<String>) { 
  ...
}

on command-line tool. I did install kotlin compiler, set up the path. All I have to do is to figure out how to pass args parameter through command line and cannot find a way to do that.

I've looked through kotlin compiler options and how to run kotlin file on command-line and it did not help at all.

Thanks in advance.

2 Answers 2

2

Just type them after the command:

java -jar myjar.jar arg_one arg_two

//OR (After compiling to jars you can specify the main class to run)
kotlin -classpath myjar.jar MyKt 'arg_one' 'arg_two'

//OR
kotlin MyKt 'arg_one' 'arg_two'

Then:

val argOne = args[0] // "arg_one"
Sign up to request clarification or add additional context in comments.

Comments

1

First you have to compile your file to a JAR:

kotlinc filename.kt -include-runtime -d output.jar

Then you can run that JAR with java:

java -jar output.jar argument0 argument1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.