system() output to a char*

int system(const char *)

How can I send output of this command (lets say the command is "pwd") to a char*? Its returning an int but I want the results of the command to be sent to a char*.


You can pipe the output of the command directly to a file by using "pwd > tempfile" as command. Another way is to use popen

FILE *output = popen("pwd", "r");

That will give you a file pointer where you can read the output from.


system("pwd > file");

system() uses "/bin/sh -c" under Linux so it can do anything a shell command line can do.


  • How to get the second value in a dropdown box based on the selected one in the first dropdown box
  • ERROR: Additional information: External table is not in the expected format
  • Git cherry-Pick a batch of commits from a file
  • console.log printing statements in the wrong order for learnyounode node.js tutorial
  • Modifying files nested in tar archive
  • Determining the length of a read stream in node js
  • Can't access Tomcat 7 Manager app when running from Eclipse
  • How do I Dispose a HttpResponseMessage in my Web Api Method?
  • For loop with if condition on multiple R functions
  • How to read piped content in C?
  • Is playing sound in Javascript performance heavy?
  • C: Incompatible pointer type initializing
  • How can the INSERT … ON CONFLICT (id) DO UPDATE… syntax be used with a sequence ID?
  • Get history of file changes from TFS to implement custom “blame”-behaviour of exceptions
  • WPF - CanExecute dosn't fire when raising Commands from a UserControl
  • Abort upload large uploads after reading headers
  • Insert into database using onclick function
  • Jenkins: How To Build multiple projects from a TFS repository?
  • How do I fake an specific browser client when using Java's Net library?
  • AES padding and writing the ciphertext to a disk file
  • VS2008 Enable C++ Exception with SEH
  • Knitr HTML Loop - Some HTML output, some R output
  • Deserializing XML into class C#
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Apache 2.4 - remove | delete | uninstall
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Data Validation Drop Down Box Arrow Disappearing
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Proper folder structure for lots of source files
  • C# - Getting references of reference
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How does Linux kernel interrupt the application?
  • python draw pie shapes with colour filled
  • Sorting a 2D array using the second column C++
  • How to Embed XSL into XML
  • java string with new operator and a literal