【问题标题】:Return value of process to String进程返回值到String
【发布时间】:2017-02-02 12:50:13
【问题描述】:

我正在尝试使用 wget 命令将页面的源返回到使用命令的字符串:

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);

但返回值为0。这是代码的输出:

result : 0

如何访问变量中wget的返回值,这里是url的源值?

【问题讨论】:

标签: scala exec system wget


【解决方案1】:

! 返回进程的退出代码(在您的情况下为0)。如果您需要该过程的输出,您应该改用!!

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-18
    • 2017-11-12
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多