mdivk
mdivk

Reputation: 3727

How to run shell command programmatically in scala

I have some shell commands that would get dynamically generated in my scala script, how can I run them inside the scala script?

Code snippet below:

var filename = xxxxxx

filename = "This File"

import sys.process._
"hdfs dfs -rm " + filename 

Literally I want to run shell command: hdfs dfs -rm "This File"

Thank you very much.

Upvotes: 0

Views: 896

Answers (1)

Alexey Novakov
Alexey Novakov

Reputation: 765

There is a method called ! to run a command, using string interpolation of the filename variable, you can run it like this:

s"hdfs dfs -rm $filename".!

See more in this answer: https://stackoverflow.com/a/6013972/6176274

Upvotes: 1

Related Questions