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.
Linux システムで実行する C プログラムを作成しています。プログラムはいくつかの Linux コマンドをシェルに渡し、txt ファイルで結果を受け取ります。
system("last >> last.txt"); system("ls -s >>ls.txt");
しかし、誰かがこれはコマンドではなくビルドインだと言ったので、「履歴」で失敗しました。
「歴史」を他のものとして渡す方法はありますか?
ありがとう!
シェルを使用して組み込みコマンドを実際に呼び出すこともできます。
system("bash -e \"history >> history.txt\"");
"bash"優先シェルに変更します。
"bash"
「history」は「cat ~/.bash_history」と同等であるため、代替手段として次を使用します。
system("cat ~/.bash_history");