るりまサーチ

最速Rubyリファレンスマニュアル検索!
144件ヒット [1-100件を表示] (0.381秒)
トップページ > クエリ:i[x] > クエリ:h[x] > クエリ:def_system_command[x]

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

ライブラリ

クラス

キーワード

検索結果

<< 1 2 > >>

Shell.def_system_command(command, path = command) -> nil (21313.0)

Shell のメソッドとして command を登録します.

...Shell のメソッドとして command を登録します.

OS上のコマンドを実行するにはまず, Shellのメソッドとして定義します.
注) コマンドを定義しなくとも直接実行できる Shell#system コマンドもあります.

@param command Shell のメソッド...
...m path command のパスを指定します。
指定しない場合はcommand と同じになります。

例)
require 'shell'
Shell.def_system_command "ls"
# ls を定義

Shell.def_system_command "sys_sort", "sort"
# sortコマンドをsys_sortとして定義

sh = Shell.n...
...ew
sh.transact {
ls.each { |l|
puts l
}
(ls("-l") | sys_sort("-k 5")).each {|l|
puts l
}
}...

Shell.alias_command(alias, command, *opts) {...} -> self (9228.0)

コマンドの別名(エイリアス)を作成します。 コマンドが無い場合は、Shell.def_system_command などであらかじめ作成します.

...コマンドの別名(エイリアス)を作成します。
コマンドが無い場合は、Shell.def_system_command などであらかじめ作成します.

@param alias エイリアスの名前を文字列で指定します.

@param command コマンド名を文字列で指定します.

@param...
...を指定します.

使用例: ls -la | sort -k 5 のような例。

require 'shell'
Shell.def_system_command("ls")
Shell.alias_command("lsla", "ls", "-a", "-l")
Shell.def_system_command("sort")
sh = Shell.new
sh.transact {
(lsla | sort("-k 5")).each {|l|
puts l
}
}...

Shell.unalias_command(alias) -> () (9212.0)

commandのaliasを削除します.

...aliasを削除します.

@param alias 削除したいエイリアスの名前を文字列で指定します。

@raise NameError alias で指定したコマンドが無い場合に発生します。

使用例: ls -la | sort -k 5 のような例。
require 'shell'
Shell.def_system_command("ls")...
...Shell.alias_command("lsla", "ls", "-a", "-l")
Shell.def_system_command("sort")
sh = Shell.new
sh.transact {
(lsla | sort("-k 5")).each {|l|
puts l
}
}
Shell.unalias_command("lsla")
begin
Shell.unalias_command("lsla")
rescue NameError => err
puts err
end...

Shell::Filter#echo(*strings) -> Shell::Filter (9206.0)

実行すると, それらを内容とする Filter オブジェクトを返します.

...ilter オブジェクトを返します.

@param strings シェルコマンド echo に与える引数を文字列で指定します。

動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(fi...
...le).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}...

Shell::Filter#cat(*files) -> Shell::Filter (6306.0)

実行すると, それらを内容とする Filter オブジェクトを返します.

...る Filter オブジェクトを返します.

@param files シェルコマンド cat に与えるファイル名を文字列で指定します。

動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!...
...cat(file).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}...

絞り込み条件を変える

Shell::Filter#tee(file) -> Shell::Filter (6306.0)

実行すると, それらを内容とする Filter オブジェクトを返します.

...る Filter オブジェクトを返します.

@param file シェルコマンドtee に与えるファイル名を文字列で指定します。

動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!...
...cat(file).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}...

Shell#echo(*strings) -> Shell::Filter (6206.0)

実行すると, それらを内容とする Filter オブジェクトを返します.

...ilter オブジェクトを返します.

@param strings シェルコマンド echo に与える引数を文字列で指定します。

動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(fi...
...le).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}...

Shell::CommandProcessor#echo(*strings) -> Shell::Filter (6206.0)

実行すると, それらを内容とする Filter オブジェクトを返します.

...ilter オブジェクトを返します.

@param strings シェルコマンド echo に与える引数を文字列で指定します。

動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(fi...
...le).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}...

Shell::Filter#glob(pattern) -> Shell::Filter (6206.0)

実行すると, それらを内容とする Filter オブジェクトを返します.

...Filter オブジェクトを返します.

@param pattern シェルコマンド glob に与えるパターンを指定します。
パターンの書式については、Dir.[] を参照してください。

動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell....
...new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}

@see Dir.[]...

Shell::Filter#|(filter) -> object (6148.0)

パイプ結合を filter に対して行います。

...を filter に対して行います。

@param filter Shell::Filter オブジェクトを指定します。

@return filter を返します。

使用例
require 'shell'
Shell.def_system_command("tail")
Shell.def_system_command("head")
Shell.def_system_command("wc")
sh = Shell.new
sh.tra...
...nsact {
i
= 1
while i <= (cat("/etc/passwd") | wc("-l")).to_s.chomp.to_i
puts (cat("/etc/passwd") | head("-n #{i}") | tail("-n 1")).to_s
i
+= 1
end
}...

絞り込み条件を変える

Shell::Filter#system(command, *opts) -> Shell::SystemCommand (6106.0)

command を実行する.

...で指定します。

@param opts command のオプションを文字列で指定します。複数可。

使用例:

require 'shell'
Shell.verbose = false
sh = Shell.new

print sh.system("ls", "-l")
Shell.def_system_command("head")
sh.system("ls", "-l") | sh.head("-n 3") > STDOUT...

Shell::Filter#to_a -> [String] (6106.0)

実行結果を文字列の配列で返します。

...実行結果を文字列の配列で返します。

require 'shell'
Shell.def_system_command("wc")
sh = Shell.new
puts sh.cat("/etc/passwd").to_a...

Shell::Filter#to_s -> String (6106.0)

実行結果を文字列で返します。

...実行結果を文字列で返します。

require 'shell'
Shell.def_system_command("wc")
sh = Shell.new

sh.transact {
puts (cat("/etc/passwd") | wc("-l")).to_s
}...

Shell::Filter#<(src) -> self (6006.0)

srcをフィルタの入力とする。 srcが, 文字列ならばファイルを, IOオブジェクトであれ ばそれをそのまま入力とする。

...ルを, IOオブジェクトであれ
ばそれをそのまま入力とする。

@param src フィルタの入力を, 文字列もしくは,IO オブジェクトで指定します。

使用例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
(sh.head("-n 30...

Shell::Filter#>(to) -> self (6006.0)

toをフィルタの出力とする。 toが, 文字列ならばファイルに, IOオブジェクトであれ ばそれをそのまま出力とする。

...に, IOオブジェクトであれ
ばそれをそのまま出力とする。

@param to 出力先を指定します。文字列ならばファイルに,IOオブジェクトならばそれに出力します。

使用例
require 'shell'
Shell.def_system_command("tail")
sh = Shell.new
sh.tran...
...sact {
(sh.tail("-n 3") < "/etc/passwd") > File.open("tail.out", "w")
#(sh.tail("-n 3") < "/etc/passwd") > "tail.out" # と同じ.
}...

絞り込み条件を変える

Shell::Filter#>>(to) -> self (6006.0)

toをフィルタに追加する。 toが, 文字列ならばファイルに, IOオブジェクトであれば それをそのまま出力とする。

...に, IOオブジェクトであれば
それをそのまま出力とする。

@param to 出力先を指定します。文字列ならばファイルに、IOオブジェクトならばそれに出力します。

使用例
require 'shell'
Shell.def_system_command("tail")
sh = Shell.new
sh.tr...
...ansact {
(sh.tail("-n 3") < "/etc/passwd") >> "tail.out"
#(sh.tail("-n 3") < "/etc/passwd") >> File.open("tail.out", "w") # でも同じ。
}...

Shell::Filter#out(dev = STDOUT, &block) -> () (6006.0)

Shell#transact を呼び出しその結果を dev に出力します。

...Shell#transact を呼び出しその結果を dev に出力します。

@param dev 出力先をIO オブジェクトなどで指定します。

@param block transact 内部で実行するシェルを指定します。


使用例:
require 'shell'
Shell.def_system_command("head")
sh = Shell...
....new
File.open("out.txt", "w"){ |fp|
sh.out(fp) {
system("ls", "-l") | head("-n 3")
}
}...
<< 1 2 > >>