草庐IT

COMMAND_LINE

全部标签

ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃

为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

ruby - Rubocop 规则 : Never use 'do' with multi-line 'while

我有以下代码#coloursarandomcellwithacorrectcolourdefcolour_random!whiletruedocol,row=rand(columns),rand(rows)cell=self[row,col]ifcell.empty?thencell.should_be_filled??cell.colour!(1):cell.colour!(0)breakendendend做什么并不重要,尽管它应该很明显。关键是Rubocop给了我一个警告Neveruse'do'withmulti-line'while为什么我不应该那样做?那我该怎么办呢?

ruby - 为 IO::popen 拯救 "command not found"

当我将IO::popen与不存在的命令一起使用时,我在屏幕上打印了一条错误消息:irb>IO.popen"fakefake"#=>#irb>(irb):1:commandnotfound:fakefake有什么方法可以捕获此错误,以便我可以在脚本中进行检查? 最佳答案 是:升级到ruby​​1.9。如果您在1.9中运行它,则会引发Errno::ENOENT,您将能够拯救它。(编辑)这是在1.8中的一种hackish方式:error=IO.pipe$stderr.reopenerror[1]pipe=IO.popen'qwe'#

ruby 选项解析器 : hiding help text for a command option

Ruby“OptionParser将根据此描述自动为您生成帮助屏幕”[http://ruby.about.com/od/advancedruby/a/optionparser.htm]有没有办法删除命令选项的帮助文本。我可以使用隐藏命令,但有一个命令选项(开关)并隐藏其帮助上下文。 最佳答案 我能够为此拼凑出一个不太优雅的解决方案。它将隐藏主帮助屏幕中的选项,听起来它可能符合您的需要:require'optparse'options={}OptionParser.newdo|opts|opts.banner="Usage:#{$0}

ruby - 在 ruby​​ 中,file.readlines.each 并不比 file.open.each_line 快,为什么?

只是为了分析我的iis日志(奖励:碰巧知道iislog是用ASCII编码的,errrr..)这是我的ruby代码1.readlinesDir.glob("*.log").eachdo|filename|File.readlines(filename,:encoding=>"ASCII").eachdo|line|#commentlineifline[0]=='#'nextelseline_content=line.downcase#justcareaboutfirstonematched_keyword=keywords.select{|e|line_content.include?e

ruby-on-rails - rbenv : bundle: command not found on production server

我正在尝试部署Rails应用程序,但遇到错误DEBUG[1a70ba92]Command:cd/home/deploy/myapp/releases/20140615090226&&(PATH=$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATHRBENV_ROOT=~/.rbenvRBENV_VERSION=2.1.2~/.rbenv/bin/rbenvexecbundleinstall--binstubs/home/deploy/myapp/shared/bin--path/home/deploy/myapp/shared/bundle--withou

ruby-on-rails - 我得到 rvm : command not found after installation of rvm

我知道上面的问题是很常见的问题。我已经阅读了关于这个主题的多篇文章。但是我没有得到任何解决方案。我已经在本地安装了rvm。我们已经有了安装文件。所以进入文件夹并运行安装命令。$./install然后我检查了Users主文件夹中的./rvm文件夹$cd~/.rvm文件夹存在。至此安装成功。现在我在命令行输入rvm$rvm我正在低于异常$rvm-sh:rvm:commandnotfound在阅读了stackoverflow中有关此问题的多篇文章后,我了解到我必须在.bash_profile中添加以下行,因为我使用的是MacOSX10.7.3[[-s"$HOME/.rvm/scripts/r

ruby each_line 也读取换行符?

我正在尝试从文本文件中读取数据并将其与帖子字符串连接起来。当文件中只有一行时,它工作正常。但是有2行,我的请求失败了。each_line是否读取换行符?我该如何纠正它?File.open('sfzh.txt','r'){|f|f.each_line{|row|send(row)}我确实通过拆分和额外的定界符绕过了这个问题。但它看起来很丑。 最佳答案 是的,each_line包括换行符。但是您可以使用chomp轻松剥离它们:File.foreach('test1.rb')do|line|sendline.chompend

ruby-on-rails - 错误 : Command 'test' not recognized

我在Rails服务器中使用c9.io进行开发。我执行railstest并且它可以正常工作。第二天,我执行相同的命令,但出现错误:无法识别命令“测试”我没有做任何更改。我怎样才能恢复这个命令?注意:rake测试完美运行,但ruby​​页面http://edgeguides.rubyonrails.org/testing.html和ruby​​onrails教程,MichaelHartlhttps://www.railstutorial.org/book/static_pages谈论railstest命令,它对我有用2天。这是我的gem文件source'https://rubygems.o

ruby - Git Bash 给出 sh.exe : ruby: command not found

我在WindowsVistaBusiness上使用GitBash。我正在尝试安装Redmine。基本上在第4步,我需要在安装bundler之前安装RubyGem作为依赖项安装的一部分(http://www.redmine.org/projects/redmine/wiki/RedmineInstall)。我从https://rubygems.org/pages/download下载了ruby​​gems-2.2.2.zip.然后我将文件解压缩到桌面上的一个文件夹中。在GitBash中,我输入了rubysetup.rb,我得到了sh.exe:ruby​​:commandnotfound。