0

I have a Scala code in which i am creating a new file in resource directory.

And then doing some work around with that new file. (in my case splitting the file)

logger.debug("Run training process...")
InferTopics.main(("--input " + tmpDir + "new_corpus.mallet --inferencer " + tmpDir + "inferencer " + "--output-doc-topics " + tmpDir + "doc-topics-new.txt --num-iterations 1000").split(" "))
logger.debug("Inferring process finished.")

In the below code of line I am trying to split the new file created above however file is not available unless I am terminating the code.

val lines = Source
       .fromResource("doc-topics-new.txt")
       .getLines
       .toList
       .drop(1) match {
       case Nil => List.empty
       case x :: xs => x.split(" ").drop(2).mkString(" ") :: xs
     }

In a gist, The problem is File is only getting created once i am terminating the code and not after the call of code to create the file.

Please note: The new file is getting generated by calling a mallet module, which infer an input file and create a new one 'doc-topics-new.txt'.

Any suggestion

danD
  • 666
  • 1
  • 7
  • 29
  • 1
    Can you show code, where you are creating file? – Krzysztof Atłasik Jun 03 '19 at 13:56
  • I am calling an external API (mallet) to create the file. which is "InferTopics.main(("--input " + tmpDir + "new_corpus.mallet --inferencer " + tmpDir + "inferencer " + "--output-doc-topics " + tmpDir + "doc-topics-new.txt --num-iterations 1000").split(" "))". The same call in java code creates the output file however when i am trying to do the same in scala the file is not getting generated unless i am terminating the code. – danD Jun 03 '19 at 14:23
  • So you need to kill mallet process in order for the file to be available or scala process? – Krzysztof Atłasik Jun 03 '19 at 14:56
  • could you please suggest, how can i kill that process – danD Jun 03 '19 at 16:07
  • Ok, to sum up, if you kill your app, then file appears? – Krzysztof Atłasik Jun 03 '19 at 19:39
  • yes If i kill my app then files appear, but i believe i need to kill just the process and then in the next line the file will be used. but i am not sure how to kill a sub process in scala – danD Jun 03 '19 at 21:07

0 Answers0