从ruby rspec运行命令行

时间:2018-05-17 01:59:10

标签: ruby shell command-line rspec

我有一个包含以下代码的spec文件,我使用rake

运行它
describe 'Running Reselience test', test_execute: true do     
    it "running deploy build access service and manage" do
       system("for i in {1..3}; do sleep 5; echo $i; done &")
       system("for i in {10..13}; do sleep 5; echo $i; done &")    
    end 
end

运行上面的spec文件时,我在命令行中收到以下错误

i was unexpected at this time.
i was unexpected at this time.

如何在不收到上述错误的情况下运行上述批处理命令?

1 个答案:

答案 0 :(得分:0)

根据提及的https://superuser.com/questions/894475/for-do-command-gives-was-unexpected-at-this-time-when-run-from-command-prompt网址作者

在批处理文件中引用For循环变量时,需要将百分号(即:%% a),加倍,但如果在提示符处直接运行命令时执行此操作则不起作用。您需要将它们更改为单个百分号(%a)。

同样在此网址single line for statement: %%i 'unexpected at this time' 作者提到使用单个百分号

我正在使用Linux操作系统(因此无法测试您的方案)但是根据以下链接,您需要更改命令语法

网址https://www.windows-commandline.com/windows-for-loop-examples/

网址DOS FOR loop on range through command line

网址https://ss64.com/nt/for_l.html

例如

for %i in (user1 user2 user3 user4 user5 user6) do net user /delete %i

所以在你的情况下

FOR /l %i in (1,1,3) DO sleep 5 & echo %i
相关问题