Quantcast
Viewing latest article 5
Browse Latest Browse All 11

How to run shell commands from the Scala REPL

How to run shell commands from the Scala REPL

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 14.4, “How to run a shell command from the Scala REPL.”

Problem

You want to be able to run a shell command from within the Scala REPL, such as listing the files in the current directory.

Solution

Run the command using the :sh REPL command, then print the output. The following example shows how to run the Unix ls -al command from within the REPL, and then show the results of the command:


Viewing latest article 5
Browse Latest Browse All 11

Trending Articles