新手问题 请问如何使用 ruby 代码来执行.sh 文件

return · September 29, 2017 · Last by stargwq replied at September 30, 2017 · 3405 hits

我在目录的 files 文件下面写了个 test.sh 文件,现在我想在控制器中来执行这个 test.sh 文件(files/test.sh),请问该怎么写?谢谢!

Reply to mizuhashi

Open3 貌似只能对 cmd 命令吧,对这种附带路径的好像不支持吧,谢谢~

Reply to return

原来如此

Reply to return

你的 test.sh 也是 cmd,和是不是附带路径无关。系统命令只是在 $PATH 中而已,是为了方便,你也可以用其绝对路径调用。众生平等。 你需要做的是对脚本用户和脚本权限的正确设置。

Reply to gingerhot

我主要是不知道怎么写😂

command = "sh files/test.sh"
Open3.popen3(command)
#  下面的也不行
Open3.popen3(files/test.sh)

该怎样写呢?谢谢关注~

好像有个 system 方法吧,试试看。

system("sh files/test.sh")

stdout, status = Open3.capture2('/bin/sh', 'files/test.sh')

9 Floor has deleted
def remove_file(project, repo)
   `cd /var/www/tmp_code && rm -rf #{repo}*`
   ...
end
You need to Sign in before reply, if you don't have an account, please Sign up first.