在shell脚本中使用rails runner显示命令运行的输出

时间:2016-06-30 19:01:32

标签: ruby-on-rails ruby shell sh

我正在编写一个可执行的shell脚本,它使用rails runner在rails控制台中执行某些操作。如何查看ruby命令的结果并将其打印到屏幕上。

我尝试使用-v运行脚本以获得详细信息,但我仍然无法看到发生了什么。

@echo off
Title Get TTL from IP adress
set vbsfile=%Tmp%\%~n0.vbs
set IP_File=E:\vb-ping\ip.txt
set LogFile=Log.txt
If Exist %LogFile% Del %LogFile%
For /f %%a in ('Type %IP_File%') Do ( 
     Call:VBS "%%a" & echo  %%a
    ( Call:VBS "%%a" & echo  %%a)>> %LogFile%
)
echo.
color 0A
echo Hit any key to open the LogFile "%LogFile%"
pause>nul
Start "" %LogFile%
Exit /b

:VBS 
(
    echo WScript.StdOut.Write TTL(WScript.Arguments(0^)^)
    echo '**********************************************************************************************************
    echo Function TTL(strHost^)
    echo     dim objPing, objRetStatus
    echo     set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}"^).ExecQuery _
    echo       ("select * from Win32_PingStatus where address = '" ^& strHost ^& "'"^)
    echo     for each objRetStatus in objPing
    echo         if IsNull(objRetStatus.StatusCode^) or objRetStatus.StatusCode ^<^> 0 then
    echo            Ping = False
    echo           WScript.Echo "Status code is " ^& objRetStatus.StatusCode
    echo        else
    echo            Ping = True
    echo            TTL = objRetStatus.ResponseTimeToLive 
    echo        end if
    echo     next
    echo End Function 
    echo '**********************************************************************************************************
)> "%vbsfile%"
Cscript /Nologo "%vbsfile%" "%~1"
Exit /b

1 个答案:

答案 0 :(得分:1)

使用puts
sudo rails runner "puts Model.print_something"