2014-08-29 47 views
0
运行shell命令

我想在我的Rake文件试图在Rake文件

exclusions = args.version >= "7" ? " -t [email protected]" : "" 
current_date = DateTime.now.to_s 
t.cucumber_opts = "-r Frank/features " + args.selection + (args.idiom == "ipad" ? " -t [email protected]" : " -t [email protected]") + 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' 

运行以下shell命令,当我在sh运行shell命令,我试图访问没有按”文件t已经存在了,但是如果我尝试运行cucumber_opts中的命令,它不能识别tail命令并且需要一个目录。

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

回答

0

$PATH$PWD可能不是您在从其他程序运行shell命令时所期望的。解决这个问题的最好方法是为每个引用的文件指定完整路径,可以按字面(如下例)或使用变量来引用像脚本所在的目录或用户的主目录。

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