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. CreateProcess() anomaly

CreateProcess() anomaly

Scheduled Pinned Locked Moved C / C++ / MFC
linuxhelpperlsecuritytools
1 Posts 1 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.
  • N Offline
    N Offline
    neilsolent
    wrote on last edited by
    #1

    :mad::confused: X| Hi everyone I am running the following piece of code on Windows 2000 and XP (except the code below has been simplified with error checking removed). This code spawns a child process, which writes its output to a logfile called child.log. The problem I am having is: if the child process is a command or batch file (example below), then child.log captures output of commands such as "dir", however, for any processes that are launched from the batch script, such as perl.exe, all the output is lost. I don't know where the output is going or why. I suspect I have done something wrong with handle inheritance somewhere.. any ideas?? I don't get the same problem if the child process is some other shell interpreter, such as bash.exe. ......................... SECURITY_ATTRIBUTES secAttr; secAttr.nLength = sizeof(SECURITY_ATTRIBUTES); secAttr.bInheritHandle = TRUE; secAttr.lpSecurityDescriptor = NULL; STARTUPINFO startupInfo; ::ZeroMemory((void*) &startupInfo, sizeof(STARTUPINFO)); startupInfo.cb = sizeof(STARTUPINFO); startupInfo.dwFlags = STARTF_USESTDHANDLES; PROCESS_INFORMATION processInfo; startupInfo.hStdOutput = CreateFile( "child.log", GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, &secAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_SEQUENTIAL_SCAN, NULL); startupInfo.hStdError = startupInfo.hStdOutput; CreateProcess( NULL, "test.bat", NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &startupInfo, &processInfo); // Close handle because parent process has no further need for it: CloseHandle(startupInfo.hStdOutput); .................. Example of test.bat: ---------------------------- rem test.bat rem dir command gives output in child.log, but "perl -v" does not !! dir perl -v exit 0 cheers, Neil

    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