Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. exec output

exec output

Scheduled Pinned Locked Moved C / C++ / MFC
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    marouane miftah el kheir
    wrote on last edited by
    #1

    Hi all! I want to call execlp("ls","ls","-tl",(char*)0); but I also want to redirect the output to a file or a buffer or something. does anyone know of a way to get the output from exec? by the way I tried this way of piping execlp("ls","ls","-tl",">",filename,(char*)0); but this does not work. Thanks in Advance:((:confused:

    J 1 Reply Last reply
    0
    • M marouane miftah el kheir

      Hi all! I want to call execlp("ls","ls","-tl",(char*)0); but I also want to redirect the output to a file or a buffer or something. does anyone know of a way to get the output from exec? by the way I tried this way of piping execlp("ls","ls","-tl",">",filename,(char*)0); but this does not work. Thanks in Advance:((:confused:

      J Offline
      J Offline
      Johnny
      wrote on last edited by
      #2

      Seeing as 'ls' only exists on Unix, then I will assume that is the platform you are programming for. To control the standard output/input you need to do change the target for them in the child process (you should be using fork if you are using execl). This can be achieved with the 'dup2' command: int myfd = open ("somefile.txt", O_CREAT | O_WRONLY, 0777); dup2 (myfd, STDOUT_FILENO); This re-maps the stdout output to your own file. You can then call 'execlp' to load ls, and the output will go to your file

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups