Search code examples
scalaexecsystemwget

Return value of process to String


I'm attempting to return the source of a page using the wget command to String using command :

val url: String = "https://morningconsult.com/alert/house-passes-employee-stock-options-bill-aimed-startups/"
import sys.process._
val result: String = ("wget -qO- " + url !).toString
println("result : " + result);

but return value is 0. This is output of code :

result : 0

How to access the return value of wget in a variable , in this case the source value of the url ?


Solution

  • ! returns the exit code of the process (0 in your case). If you need the output of the process you should use !! instead:

    val url = "https://morningconsult.com/alert/house-passes-employee-stock-options-bill-aimed-startups/"
    import sys.process._
    val result = ("wget -qO- " + url !!).toString
    println("result : " + result)
    

    (relevant documentation)