stdlib system() cout

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Saile
    New Member
    • Oct 2007
    • 7

    stdlib system() cout

    When you call the system function() with any parameter it prints text to the console, I wonder if you can get this text into a string variable.
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    Can you clarify your question? Do you mean use a string in your system() call instead of typing in a literal string? Do you mean storing the output of, say, another program and catching that in a string back in your C++ program?

    Comment

    • gpraghuram
      Recognized Expert Top Contributor
      • Mar 2007
      • 1275

      #3
      Originally posted by Saile
      When you call the system function() with any parameter it prints text to the console, I wonder if you can get this text into a string variable.

      You have to redirect the output of the system call to a file and then read it.
      like this
      [code=c]
      char array[100]="ls > outfile";
      system(array);

      //open and read the outfile

      [/code]

      Thanks
      Raghuram

      Comment

      • Saile
        New Member
        • Oct 2007
        • 7

        #4
        Thanks, the "> outfile" solves my question.

        Comment

        Working...