

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to execute a command and get output of command within C++ using POSIX?
Here we will see how to use the POSIX command through C++. The process is very simple, we have to use the function called system(). Inside this we have to pass string. That string will contain the POSIX command.
The syntax is like below.
system(“command”)
Example
#include <iostream> using namespace std; int main () { cout << "Print string using echo command" << endl; system("echo 'Hello World'"); cout << "Calculate math expression using bc" << endl; system("echo '22 / 7' | bc -l"); return 0; }
Output
Print string using echo command Hello World Calculate math expression using bc 3.14285714285714285714
- Related Questions & Answers
- How to execute a command and get the output of command within C++ using POSIX?
- How to work with Invoke-Command Scriptblock output?
- How to Save Command Output to a File in Linux?
- How can I execute JavaScript at the command prompt?
- Difference between Write-Output and Write-Host command in PowerShell?
- How to convert command output to the Hashtable format in PowerShell?
- How we can execute linux command with Python CGI script?
- How to exclude PSComputerName property from Invoke-Command output in PowerShell?
- How to get only the file name using find command on Linux?
- How to encrypt and decrypt a file using gpg command on linux
- Give the panel command to start a specific tablespace within a DB2 database.
- How to find the version of Java using command line?
- How to run MongoDB shell using mongos command?
- Purpose of using CHANGE command in MySQL?
- How to read a file from command line using Python?
Advertisements