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. redirecting output from console?

redirecting output from console?

Scheduled Pinned Locked Moved C / C++ / MFC
securitytutorialquestion
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.
  • 9 Offline
    9 Offline
    9ine
    wrote on last edited by
    #1

    I use some console application running it from inside VC project and I want to redirect its output to file bool runprocess(wchar_t *cmnd) { SECURITY_ATTRIBUTES sattr; memset(&sattr,0,sizeof(sattr)); sattr.nLength = sizeof(sattr); sattr.bInheritHandle = true; STARTUPINFO sInfo; memset(&sInfo,0,sizeof(sInfo)); PROCESS_INFORMATION pInfo; memset(&pInfo,0,sizeof(pInfo)); sInfo.cb = sizeof(sInfo); sInfo.dwFlags = STARTF_USESTDHANDLES; bool res = CreateProcess(0,cmnd,0,0,true,NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW,0,0,&sInfo,&pInfo); if(res) WaitForSingleObject(pInfo.hProcess, INFINITE); return res; } runprocess(L"consoleapp.exe >output"); But the file output is not created though consoleapp worked normally? How to get its output without reading hStdInput, hStdOutput from STARTUPINFO structure?

    9ine

    G 1 Reply Last reply
    0
    • 9 9ine

      I use some console application running it from inside VC project and I want to redirect its output to file bool runprocess(wchar_t *cmnd) { SECURITY_ATTRIBUTES sattr; memset(&sattr,0,sizeof(sattr)); sattr.nLength = sizeof(sattr); sattr.bInheritHandle = true; STARTUPINFO sInfo; memset(&sInfo,0,sizeof(sInfo)); PROCESS_INFORMATION pInfo; memset(&pInfo,0,sizeof(pInfo)); sInfo.cb = sizeof(sInfo); sInfo.dwFlags = STARTF_USESTDHANDLES; bool res = CreateProcess(0,cmnd,0,0,true,NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW,0,0,&sInfo,&pInfo); if(res) WaitForSingleObject(pInfo.hProcess, INFINITE); return res; } runprocess(L"consoleapp.exe >output"); But the file output is not created though consoleapp worked normally? How to get its output without reading hStdInput, hStdOutput from STARTUPINFO structure?

      9ine

      G Offline
      G Offline
      Gary R Wheeler
      wrote on last edited by
      #2

      Since you are using the STARTF_USESTDHANDLES flag, you also need to open files for standard input, output, and error, and set their HANDLE values in the STARTUPINFO structure. Also, remove the "> output" from the command line, since you are already doing the redirection.


      Software Zen: delete this;

      Fold With Us![^]

      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