Search code examples
http-redirectkotlinstdoutstdinstdio

How to redirect Kotlin stdio to files?


Is it possible to redirect Kotlin stdio to files through command line parameters, something like < input.txt > output.txt? If not, is there any simple way?

I'm using IntelliJ IDEA.


Solution

  • If you run the program with an IntelliJ IDEA run configuration, then you can configure it to save the console output to a file.

    1. Open the run configuration settings:

      Open the run configuration settings

    2. In the Logs tab, check Save console output to file and enter the file name:

      enter image description here

    Redirecting is possible for Java applications as per this Q&A, but this option seems to be missing for Kotlin. This is a known issue, please vote and follow https://youtrack.jetbrains.com/issue/KT-28854

    Redirecting the input and output with < and > is the shell feature, and passing these arguments to the JVM or your program won't make any effect.