GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::system - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. cstdlib
  3. system

最終更新日時: 2026年09月16日 22時29分34秒 (JST)
rotarymars が更新

履歴 編集

function
<cstdlib>

std::system

namespace std {
  int system( const char* command );
}

概要

ホスト環境のコマンドを呼び出す。(e.g. /bin/sh, cmd.exe)

処理系定義の値を返す。大抵は呼び出されたコマンドが返した終了ステータスになる。

コマンドがヌルポインタの場合、ホスト環境にコマンドプロセッサが存在するか確認し、存在している場合に非ゼロ値を返す。

備考

POSIXではマクロWEXITSTATUSとWSTOPSIGを使用して戻り値を分解できる。 WEXITSTATUS(戻り値) は子プロセスの終了ステータス (exitに渡した値) を評価する。 WSTOPSIG(戻り値) は子プロセスを停止したシグナル番号を評価する。

生成されるプロセスが画面の入出力を伴う場合、std::systemを呼び出す前に、std::coutの明示的なフラッシュが必要になる場合がある。

例

#include <cstdlib>
#include <fstream>
#include <iostream>

int main()
{
  std::system("ls -l >test.txt"); // "ls -l >test.txt"を実行
  std::cout << std::ifstream("test.txt").rdbuf();
}

出力例

total 16
-rwxr-xr-x 1 2001 2000 8859 Sep 30 20:52 a.out
-rw-rw-rw- 1 2001 2000  161 Sep 30 20:52 main.cpp
-rw-r--r-- 1 2001 2000    0 Sep 30 20:52 test.txt

関連項目

名前 説明
flush バッファをフラッシュする

参照

  • POSIX(IEEE Std 1003.1-2024); wait, waitpid
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.