title: Kotlin and Gradle - Reading from stdio
body: <p>I am trying to execute my Kotlin class using the command:</p>
  
  <pre><code>./gradlew -q run &lt; src/main/kotlin/samples/input.txt
  </code></pre>
  
  <p>Here is my <strong>HelloWorld.kt</strong> class:</p>
  
  <pre><code>package samples
  
  fun main(args: Array&lt;String&gt;) {
  
      println("Hello, world!")
  
      val lineRead = readLine()
      println(lineRead)
  }
  </code></pre>
  
  <p>Here is my <strong>build.gradle.kts</strong>:</p>
  
  <pre><code>plugins {
      kotlin("jvm")
      application
  }
  
  application {
      mainClassName = "samples.HelloWorldKt"
  }
  
  dependencies {
      compile(kotlin("stdlib"))
  }
  
  repositories {
      jcenter()
  }
  </code></pre>
  
  <p>The code executes, but the data contained inside the input.txt file is not displayed. Here is the output I get:</p>
  
  <pre><code>Hello, world!
  null
  </code></pre>
  
  <p>I want to be able to execute the gradlew command above and the input.txt stream be redirected to stdio. I can easily do that in C++. Once I compile my .cpp file, I can run:</p>
  
  <pre><code>./my_code &lt; input.txt
  </code></pre>
  
  <p>and it executes as expected.</p>
  
  <p>How can I achieve the same thing with Kotlin and Gradle?</p>
  
  <p><strong>Update</strong>: Based on <a href="https://discuss.gradle.org/t/why-doesnt-system-in-read-block-when-im-using-gradle/3308/2" rel="noreferrer">this answer</a>, I've tried adding this to build.gradle.kts but it is not a valid syntax:</p>
  
  <p><a href="https://i.stack.imgur.com/Al7Va.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Al7Va.png" alt="enter image description here"></a></p>