Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
464 views
in Technique[技术] by (71.8m points)

ruby - Execute bash commands from a Rakefile

I would like to execute a number of bash commands from a Rakefile.

I have tried the following in my Rakefile

task :hello do
  %{echo "World!"}
end

but upon executing rake hello there is no output? How do I execute bash commands from a Rakefile?

NOTE:This is not a duplicate as it's specifically asking how to execute bash commands from a Rakefile.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think the way rake wants this to happen is with: http://rubydoc.info/gems/rake/FileUtils#sh-instance_method Example:

task :test do
  sh "ls"
end

The built-in rake function sh takes care of the return value of the command (the task fails if the command has a return value other than 0) and in addition it also outputs the commands output.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...