Cattani Simone
Cattani Simone

Reputation: 1218

Scala, error on * (asterisk) char using scala.sys.process

I'm trying to run a command from Scala

val cmd = "scp -r /path/to/dir/* user@ip:target/dir"
print(cmd)    
cmd.!!

if I copy the command inside the terminal it works without problem, but running it using the .!! method I obtain

/path/to/dir/*: No such file or directory

What could be the problem? thanks

Upvotes: 0

Views: 174

Answers (1)

Tzach Zohar
Tzach Zohar

Reputation: 37832

Asterisk is expanded by bash, so you'll need to get bash to execute the command for you, can be done like this:

val cmd = "echo \"scp -r /path/to/dir/* user@ip:target/dir\" | bash"
print(cmd)    
cmd.!!

Upvotes: 1

Related Questions