Skip to content

Commit c2781ec

Browse files
committed
new page cstdlib/system.md
1 parent b2b7126 commit c2781ec

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

reference/cstdlib/system.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# system
2+
* cstdlib[meta header]
3+
4+
5+
```cpp
6+
int system( const char* command );
7+
```
8+
## 概要
9+
10+
11+
ホスト環境のコマンド呼び出す。(e.g. /bin/sh, cmd.exe)
12+
13+
14+
Returns an implementation-defined value (usually the value that the invoked program returns).
15+
16+
If command is a null pointer, checks if the host environment has a command processor and returns a nonzero value if and only if the command processor exists.
17+
18+
Parameters
19+
command - character string identifying the command to be run in the command processor. If a null pointer is given, command processor is checked for existence
20+
Return value
21+
Implementation-defined value. If command is a null pointer, returns a nonzero value if and only if the command processor exists.
22+
23+
Notes
24+
On POSIX systems, the return value can be decomposed using WEXITSTATUS and WSTOPSIG.
25+
26+
The related POSIX function popen makes the output generated by command available to the caller.
27+
28+
An explicit flush of std::cout is also necessary before a call to std::system, if the spawned process performs any screen I/O.
29+
30+
## 例
31+
32+
```cpp example
33+
#include <cstdlib>
34+
#include <fstream>
35+
#include <iostream>
36+
37+
int main()
38+
{
39+
std::system("ls -l");
40+
std::cout << std::ifstream("test.txt").rdbuf();
41+
}
42+
```
43+
44+
## 出力結果
45+
46+
```
47+
total 16
48+
-rwxr-xr-x 1 2001 2000 8859 Sep 30 20:52 a.out
49+
-rw-rw-rw- 1 2001 2000 161 Sep 30 20:52 main.cpp
50+
-rw-r--r-- 1 2001 2000 0 Sep 30 20:52 test.txt
51+
```
52+

0 commit comments

Comments
 (0)