std::system(3)
π std::system(3) π
okay so this is the std::system(3) page from the C++ Standard Libary manual, and bestie, it's giving "call the host environment's command processor" energy. no cap, we're keeping every single detail. π«Ά
β¨ NAME β¨
std::systemβ literallystd::system, the main character. π
πΈ Synopsis πΈ
Defined in header <cstdlib>:
int system( const char* command );
Okay so what it does: it calls the host environment's command processor (think /bin/sh, cmd.exe) with the parameter command. It returns an implementation-defined value β usually the value that the invoked program returns. π
If command is a null pointer, it checks whether the host environment has a command processor, and returns a nonzero value if and only if the command processor exists. β¨
π Parameters π
commandβ a character string identifying the command to be run in the command processor. If a null pointer is given, the command processor is checked for existence. π¦
π Return value π
Implementation-defined value, bestie. If command is a null pointer, it returns a nonzero value if and only if the command processor exists. Periodt. π
π¦ Notes π¦
- On POSIX systems, the return value can be decomposed using
WEXITSTATUSandWSTOPSIG. π - The related POSIX function
popenmakes the output generated bycommandavailable to the caller. π¬ - An explicit flush of
std::coutis also necessary before a call tostd::system, if the spawned process performs any screen I/O. π
β Example β
Run this code, bestie:
// Run this code
#include <cstdlib>
#include <fstream>
#include <iostream>
int main()
{
std::system("ls -l >test.txt"); // executes the UNIX command "ls -l >test.txt"
std::cout << std::ifstream("test.txt").rdbuf();
}
π Possible output π
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
π See also π
C documentation for system β that's the related C docs, go sip that tea too. π΅
π source: http://cppreference.com Β· version/date: 2024.06.10 Β· xoxo, your Unix bestie π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms