🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #11492

How do I get the correct exit code from CreateProcess()?

#11492
From: Jerri Chiu
Date: Fri, 06 Feb 2004 02:07
46 lines
2352 bytes
Hi,

I have a GUI program (BCB6) that executes an RSH command, I am 
using CreateProcess() to do it, so that I can hide the DOS 
window, but I am not able to get the correct exit status of the 
RSH.  It always returns true, even if I disabled the access, in 
the command prompt, it would yield a 'Access Denied' error.  

I also tried to pipe the output to a file, so that I can read it, except this file ends up on the UNIX server, where the 
script I am trying to RSH is.  I also try to read the output
parameters of Si and GetExitCodeProcess(), none worked.

Any suggestion is helpful..!

Thanks,
Jerri

Here's my code:
----------------------------------------------------------------
strCommand = "rsh host1 -l user1 -n ls";
STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&pi, 0, sizeof(pi));
memset(&si, 0, sizeof(si));
si.cb = sizeof (si);
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
si.wShowWindow = SW_HIDE;
si.hStdOutput =  newstdout;
si.hStdError = newstdout;
DWORD dEXIT;
nResult = CreateProcess(0, strCommand.c_str(), 0, 0, 0, 0, 0, 
                       0, &si, &pi);
if (nResult == 1)
{
    WaitForSingleObject(pi.hProcess, INFINITE);

    GetExitCodeProcess(pi.hProcess, &dEXIT);
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
}
else
    ShowMessage("Could not send the message due to system 
                 errors");

----------------------------------------------------------------
Technical Details
Message-ID: <4022f6f3$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,245592ad3cfcc9ac,start
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-02-05 18:11:23 PST
From: "Jerri Chiu" <jejesan@hotmail.com>
Sender: "Jerri Chiu" <jejesan@hotmail.com>
Reply-To: "Jerri Chiu" <jejesan@hotmail.com>
Subject: How do I get the correct exit code from CreateProcess()?
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 65.207.116.227     
NNTP-Posting-Host: 207.105.83.66
Message-ID: <4022f6f3$1@newsgroups.borland.com>
Date: 5 Feb 2004 18:07:47 -0800
X-Trace: newsgroups.borland.com 1076033267 207.105.83.66 (5 Feb 2004 18:07:47 -0800)
Lines: 48
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail