Simular la entrada desde stdin cuando se ejecuta un programa en intellij


¿Hay alguna forma de configurar los args de la línea de comandos a intellij para la redirección stdin?

Algo parecido a:

Ejecutar / Editar Ejecutar Configuraciones / Parámetros de Script

/shared/java/paf-rules.properties 2 < /shared/java/testdata.csv
Author: javadba, 2013-08-26

2 answers

Desafortunadamente, no - al menos no directamente en configuraciones de ejecución.

Lo mejor que puedes hacer, afaik, es:

  • Modifique su script / programa para que se ejecute sin args (reads System.in) o con un argumento filename (reads the file)

  • Haga un script / programa de envoltura que actúe de la manera anterior.

Espero que esto ayude,

Vikingsteve

 15
Author: vikingsteve,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-08-26 12:12:17

Aquí hay una plantilla para una solución que tiene opciones para:

  • stdin
  • file
  • "heredoc" dentro del programa (muy probablemente útil para las pruebas)

.

  val input = """ Some string for testing ... """

  def main(args: Array[String]) {
    val is = if (args.length >= 1) {
      if (args(0) == "testdata") {
        new StringInputStream(input)
      } else {
        new FileInputStream(args(0))
      }
    } else {
      System.in
    }
    import scala.io._
    Source.fromInputStream(is).getLines.foreach { line =>

Este fragmento requiere el uso de un StringInputStream-y aquí está:

  class StringInputStream(str : String) extends InputStream {
    var ptr = 0
    var len = str.length
    override def read(): Int = {
        if (ptr < len) {
          ptr+=1
          str.charAt(ptr-1)
        } else {
         -1
        }
    }
  }
 1
Author: javadba,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-10-29 14:29:10