有点愚蠢的问题,但我无法从ruby脚本运行git命令.我需要寻找东西吗?
脚本的简单示例:
checkout = %x("/usr/bin/git version")
puts checkout
Run Code Online (Sandbox Code Playgroud)
输出:
sh: /usr/bin/git version: No such file or directory
Run Code Online (Sandbox Code Playgroud)
如果我从cmd行运行命令它可以工作:
git version 1.7.9.5
Run Code Online (Sandbox Code Playgroud)
任何输入赞赏.谢谢.
你可以使用Kernel#system或Kernel #exec或者引用``:
$> irb
=> `git status`
=> "# On branch develop\nnothing to commit, working directory clean\n"
=> system('git version')
=> git version 1.8.3.4 (Apple Git-47)
=> exec('git version')
=> git version 1.8.3.4 (Apple Git-47)
Run Code Online (Sandbox Code Playgroud)
在脚本中:
#!/usr/bin/env ruby
puts system('git version')
puts `git version`
puts exec('git version')
Run Code Online (Sandbox Code Playgroud)
输出:
git version 1.8.3.4 (Apple Git-47)
true
git version 1.8.3.4 (Apple Git-47)
git version 1.8.3.4 (Apple Git-47)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5081 次 |
| 最近记录: |