0

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.

mdivk
  • 3,545
  • 8
  • 53
  • 91

1 Answers1

1

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

Alexey Novakov
  • 744
  • 6
  • 20