Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ユーザーが入力するシェルコマンドをいくつか実行する必要があります。安全だと思われる方法を 1 つ見つけました: system *%W(ls #{file}) [here]。
system *%W(ls #{file})
そのコマンドの出力を取得する必要があるため、単に使用することはできませんsystem。バッククォート``または forのコマンドをサニタイズする方法はあり%x[]ますか?
system
``
%x[]
IO::popenの代わりに必要ですsystem。文字列の配列を渡して、シェルなしでコマンドを呼び出すこともできreadます。また、結果のIOオブジェクトから実行することもできます。
IO::popen
read
stderrも読みたい場合はopen3、IOの代わりにモジュールを使用してください。
open3
Ruby がサポートしていない、実行しているシェル コマンドの種類は何ですか? ファイルを一覧表示する場合は、Dirを使用します