Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a rake task fail if system call return error

I have a Rakefile that I use to automate some tasks in my project.

Inside some tasks, I call system, but, even if the process return an error, task continues without any issue.

How can I avoid that? I want to make rake exit when some subprocess return an error.

Thanks in advance

like image 672
caarlos0 Avatar asked Dec 21 '22 12:12

caarlos0


2 Answers

You can evaluate the return value of system

system('inexistent command') or exit!(1)
puts "This line is not reached"
like image 58
Pablo Fernandez heelhook Avatar answered Jan 05 '23 21:01

Pablo Fernandez heelhook


sh is the Rake way to call a command. It will fail with a neat message. Compared with system, sh prints out the command as well.

like image 31
Franklin Yu Avatar answered Jan 05 '23 22:01

Franklin Yu