浏览 3306 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2011-09-27
最后修改:2011-09-27
1.子进程main.rb
ENV["ttt"]="yanzilee9292" system 'ruby t.rb' 2.子进程t.rb
puts ENV["ttt"] 3.运行
ruby main.rb 这样控制台会打印出yanzilee9292
Environment variables are variables passed to programs by the command line or the graphical shell. Though there are a number of environment variables that only affect the command line or graphical shell itself (such as PATH or HOME), there are also several that directly affect how Ruby scripts execute.
Accessing Environment Variables from Ruby
Ruby has direct access to environment variables via the ENV hash. Environment variables can be directly read or written to by using the index operator with a string argument. Note that writing to environment variables will only have an effect on child processes of the Ruby script. Other invocations of the script will not see the changes in environment variables.
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2011-09-27
最简单的进程通讯是用管道嘛:
hooopo@hooopo:~$ cat a.rb #!/usr/bin/env ruby puts "Hello World" hooopo@hooopo:~$ cat b.rb #!/usr/bin/env ruby puts gets * 10 hooopo@hooopo:~$ ./a.rb|./b.rb Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World |
|
返回顶楼 | |
发表时间:2011-09-27
这种方法也可以的 考虑到不同操作系统,Ruby的环境变量封装了一层,使用的时候更加简单
|
|
返回顶楼 | |