ruby在win下面执行cmd中的操作的时候通常用什么方法

Python011

ruby在win下面执行cmd中的操作的时候通常用什么方法,第1张

在windows下启动JBoss服务器,需要在命令行中输入run.bat。但是运行后如果你想停止服务器,可能的做法就是直接按Ctrl+C键强行终止服务器,显然这种方式是不友好的。另一种方法就是再开一个cmd窗口,进入Jboss的bin目录,然后键入shutdown.bat -S. 这样毕竟费时费力,如果能像Linux下在命令行的后面加一个&让它在后台运行,要关闭时就不用另开窗口直接输入相应的关闭命令就好了。答案就在下面:

在执行的命令前加上start /b,比如start /b run.bat。就相当于Linux下的run.sh &。

先安装rubyinstaller,下载并解压DevKit,注意,这两个版本要对应,网页上有说明(http://rubyinstaller.org/downloads/),解压DevKit后,打开目录,运行devkitvars.bat(是不是必须的不确定)。

打开cmd,进入DevKit的解压目录

ruby dk.rb

---

Configures an MSYS/MinGW based Development Kit (DevKit) for

each of the Ruby installations on your Windows system. The

DevKit enables you to build many of the available native

RubyGems that don't yet have a binary gem.

Usage: ruby dk.rb COMMAND [options]

where COMMAND is one of:

init prepare DevKit for installation

review review DevKit install plan

install install required DevKit executables

and 'install' [options] are:

-f, --force overwrite existing helper scripts

-------------

ruby dk.rb init

---

Initialization complete! Please review and modify the auto-generated

'config.yml' file to ensure it contains the root directories to all

of the installed Rubies you want enhanced by the DevKit.

--------------------------------

ruby dk.rb install

---

Invalid configuration or no Rubies listed. Please fix 'config.yml'

and rerun 'ruby dk.rb install'

如果出现的是这个,则需要修改config.yml

加入

- C:\Ruby200-x64

---

[INFO] Updating convenience notice gem override for 'C:/Ruby200-x64'

[INFO] Installing 'C:/Ruby200-x64/lib/ruby/site_ruby/devkit.rb'

这是对的

---------------------

gem install ruby-debug-ide

---

Temporarily enhancing PATH to include DevKit...

Building native extensions. This could take a while...

Successfully installed ruby-debug-ide-0.4.17

Parsing documentation for ruby-debug-ide-0.4.17

Installing ri documentation for ruby-debug-ide-0.4.17

1 gem installed

system(“.ruby”)或者load 'another.rb'

具体代码如下:

# 返回ls的输出

s=`ls`

cmd= "ls"

s= `#{cmd}`

# 返回true or false

s= system('ls')

cmd= 'ls'

s= system(cmd)

#返回输出

s= %x[uptime]

#用top进程替换当前ruby进程

exec "top"

cmd = 'top'

exec cmd