shellexecute and nslookup

hi guys,

i am trying to call shellexecute
in VC6 to execute "nslookup" and return the results string back to a variable...
how can I do that?
Shellexecutes only results a HINSTANCE...
pls give a code example if possible.
Note: it is used in a cgi (.exe) program

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

'ShellExecute()' is not a good solution for this.


      HANDLE hProcess;
      int hStdOut;
      int hStdOutPipe[2];

      // Create the pipe
      if(_pipe(hStdOutPipe, 512, O_BINARY | O_NOINHERIT) == -1)
         return    1;

      // Duplicate stdout handle (next line will close original)
      hStdOut = _dup(_fileno(stdout));

      // Duplicate write end of pipe to stdout handle
      if(_dup2(hStdOutPipe[WRITE_HANDLE], _fileno(stdout)) != 0)
         return    2;

      // Close original write end of pipe

      // Spawn process
      hProcess = (HANDLE)spawnlp(P_NOWAIT, "nslookup.exe",
       "", NULL);

      // Duplicate copy of original stdout back into stdout
      if(_dup2(hStdOut, _fileno(stdout)) != 0)
         return    3;

      // Close duplicate copy of original stdout

         int nOutRead;
         while    (nExitCode == STILL_ACTIVE)
            nOutRead = read(hStdOutPipe[READ_HANDLE],
             szBuffer, OUT_BUFF_SIZE);
               // do something with the output of 'nslookup' that is contained
               // in szBuffer

            if(!GetExitCodeProcess(hProcess,(unsigned long*)&nExitCode))
               return 4;


Feel free to ask if you encounter problems!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Haho2Author Commented:

does this require MFC?
No, this actually doesn't require MFC at all ;-)

But you're still free to use MFC if you want to...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.