Hello! I don't know if this is the place to ask, b...
# announcements
f
Hello! I don't know if this is the place to ask, but I was wondering if there is any way to print the output of a kts scratch file to the console or to somewhere I can copy it. I'm using the classpath of a project I'm working on and the script has external dependencies (cannot be run independently). This is how it looks like:
Copy code
val now = DateTime(DateTimeZone.UTC)
val inTwoHours = now + Duration.standardHours(2)
println(inTwoHours.millis)
Very simple, I just want to copy the time in millis and put it in another file I'm messing around with. However, when I run the scratch file it evaluates perfectly fine but shows the output to the right of the
println
statement which I cannot copy or select. I really like the ideas of scratch files and I believe it to be an invaluable tool when doing some manual testing and experimentation but I cannot seem to find how to just print it to the normal console. Anyone has any clue? (Using IntelliJ Ultimate)
t
I've had the same kind of problem. I noticed that there is a limit to the number of lines that can be displayed onto the scratch file. If you add a couple of useless (long?) lines at the beginning of the script, a "Scratch Output" window may open in IntelliJ, making it easier for you to copy/paste what you need.
Maybe you could have better answers on the dedicated #intellij channel.
f
Oh, that was unexpected, I tried
Copy code
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import org.joda.time.Duration

data class RandomStuff(val randomStuff: RandomStuff?)

val rnd = RandomStuff(RandomStuff(RandomStuff(RandomStuff(RandomStuff(RandomStuff(RandomStuff(RandomStuff(RandomStuff(RandomStuff(RandomStuff(RandomStuff(null))))))))))))

val now = DateTime(DateTimeZone.UTC)
val inTwoHours = now + Duration.standardHours(2)
println(inTwoHours.millis)
And I actually got a scratch window open. It doesn't print the line in the console though, but it prints
scratch.kts:7 val rnd: Scratch.RandomStuff
Interesting, thanks for taking your time with some directions 🙂
n
there is a feature request in your tracker https://youtrack.jetbrains.com/issue/KT-23989. Feel free to vote.
f
Thanks for the link, voted! 🙂