试图在Rakefile中运行shell命令

时间:2014-08-29 09:44:27

标签: ruby shell cucumber rake

我正在尝试在我的RakeFile中运行以下shell命令

exclusions = args.version >= "7" ? " -t ~@failing-scenario"  : ""
current_date = DateTime.now.to_s
t.cucumber_opts = "-r Frank/features " + args.selection + (args.idiom == "ipad" ? " -t ~@iphone" : " -t ~@ipad") + exclusions  + " --out ci_artifacts/frank_results"+current_date+".txt --format pretty --format html --out ci_artifacts/frank_results.html --format junit --out ci_artifacts"
sh 'tail -n 3 ci_artifacts/frank_results" + current_date + ".txt >> frank_runtimes.txt'

当我在sh中运行shell命令时,我正在尝试访问的文件不再存在,但是如果我尝试在cucumber_opts中运行该命令,则它无法识别tail命令并期望一个目录。

基本上我要做的就是保存Frank的所有输出,然后获取实际的输出时间并将它们保存在不同的文件夹中。

1 个答案:

答案 0 :(得分:0)

从其他程序运行shell命令时,

$PATH$PWD可能不是您所期望的。解决此问题的最佳方法是为您引用的每个文件指定完整路径,可以是字面上(下面的示例),也可以使用变量来引用脚本所在的目录或用户的主目录。

sh '/usr/bin/tail -n 3 /path/to/ci_artifacts/frank_results" + current_date + ".txt >> /path/to/frank_runtimes.txt'