Skip to content

Commit d9bed5a

Browse files
Merge pull request #504 from mdipirro/scala-406
SCALA-406 Add code for os-lib article
2 parents 4c738a5 + 2941d3b commit d9bed5a

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ lazy val scala_libraries_3 = (project in file("scala-libraries-3"))
280280
libraryDependencies ++= Seq(
281281
"org.apache.logging.log4j" %% "log4j-api-scala" % "12.0",
282282
"org.apache.logging.log4j" % "log4j-core" % "2.13.0" % Runtime
283-
)
283+
),
284+
libraryDependencies += "com.lihaoyi" %% "os-lib" % "0.8.1"
284285
)
285286

286287
lazy val scala_strings = (project in file("scala-strings"))
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.scala.os
2+
3+
object OsApp extends App {
4+
val ls = os.proc("ls", "-l").call()
5+
println(ls.exitCode)
6+
println(ls.out.text())
7+
println(ls.err.text())
8+
9+
os.proc("ls", "-l", "dir").call()
10+
11+
os.proc("ls", "-l", "dir").call(check = false)
12+
13+
val lines = os.read(os.pwd / "LICENSE").linesIterator.size
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.scala.os
2+
3+
import scala.io.Source
4+
import scala.sys.process._
5+
6+
object ScalaSysApp extends App {
7+
val output = "ls -l".!!
8+
println(output)
9+
10+
// This will print the standard output of the "ls -l command", even though we didn't ask for it!
11+
val result = Seq("ls", "-l").!
12+
13+
val outputErr = "ls -l dir".!!
14+
val resultErr = "ls -l dir".!
15+
16+
val source = Source.fromFile("./LICENSE")
17+
val lines = source.getLines.size
18+
source.close()
19+
}

0 commit comments

Comments
 (0)