Thread: dup question - file io

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    956
    You don't have to worry about redirecting stdout back to your terminal after netstat runs because execl does not return to your program (unless the command cannot be executed). I noticed that you're redirecting stdout to string.txt in the execl call anyway, which ignores your previous redirection. Why don't you use the system() function? It returns back to your program after the command exits.

    Then again, do you really need to convert your shell script to C in the first place? Unless you need to do something that you can't do in a script very easily (like a GUI), I'd leave it as a script. Performance isn't an issue because most processing time is spent in the subprograms, not the script itself.

    Or...could you call your script from C (with system())? That's another option.

    Edit: I forgot to mention the popen()/pclose() functions. These let you run a program and read from its output (or write to its input) as if it were a regular file without using a temporary file. These are POSIX standard functions. You would have to use about 3 pages of Win32 API code to do the same thing in the Windows world.
    Last edited by christop; 09-17-2012 at 08:08 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ File Question
    By iGuardian in forum C++ Programming
    Replies: 4
    Last Post: 10-27-2011, 12:59 PM
  2. Question about file IO
    By Raigne in forum C++ Programming
    Replies: 14
    Last Post: 05-15-2011, 06:30 PM
  3. FILE* question
    By keira in forum C Programming
    Replies: 22
    Last Post: 12-02-2007, 03:51 AM
  4. Newbish Question file reading question....
    By kas2002 in forum C Programming
    Replies: 23
    Last Post: 05-17-2007, 12:06 PM
  5. File question-Testing if file exists
    By fuh in forum C++ Programming
    Replies: 2
    Last Post: 01-28-2003, 07:11 PM

Tags for this Thread