CreateProcess CreatePipe - gather Stderr output not working

Im trying to create a process and send the output to a pipe which I
read after the
process runs so I can see whats wrong.  In this case Im trying to call
it with pscp
(which is why I hardcoded the error Im looking for btw).  Ive tried
googling this and
Ive seen many variations of this code, but so far I cant get it to
work the way I was
expecting it to.

In my debug output, ReadFile Avail <0> is as far as it gets and then
'hangs'.
I know its hanging because when I do it in the command line It also
hangs with the
string Im looking for, "Server refused our key", but I cant see why
the following code
isnt getting my Stderr output as I want.  And yes, Im a newbie still.

Id appreciate any help on getting this to work and bulletproofing it
more also.
Thanks

bool doSystem(LPSTR cmd)
{
	HANDLE read_stderr, wr_stderr;

        STARTUPINFO si;
	ZeroMemory(&si, sizeof(si));
	si.cb = sizeof(si);	// Must set the size of structure

	PROCESS_INFORMATION pi;
	SECURITY_ATTRIBUTES sa;
	sa.nLength = sizeof(SECURITY_ATTRIBUTES);
       sa.bInheritHandle = FALSE;
       sa.lpSecurityDescriptor = NULL;

       if (!CreatePipe(&read_stderr, &wr_stderr, &sa, 0))  //create
stderr pipe
       {
 		dmsg(TERR, "CreatePipe %d", GetLastError());
                return false;
       }

      si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
      si.wShowWindow = SW_HIDE;
      si.hStdError = wr_stderr;

	BOOL ret = CreateProcess(NULL, cmd, NULL, NULL, FALSE,
                            CREATE_NEW_CONSOLE, //CREATE_NO_WINDOW,
			NULL, NULL, &si, &pi);
	if (!ret)
	{
		dmsg(TERR, "CreateProcess FAILED");
                return false;
        }
	//WaitForSingleObject(pi.hProcess, INFINITE);

	dmsg(TINFO, "Process Started");

	char buf[MAX_BUF];
	DWORD bread, avail;

	if (!PeekNamedPipe(read_stderr, buf, MAX_BUF - 1, &bread, &avail,
NULL))
	{
		dmsg(TERR, "PeekNamedPipe stderr");
       }
	else
	{
		dmsg(TINFO, "ReadFile Avail <%d>", avail);
		ReadFile(read_stderr, buf, 1023, &bread, NULL);
		dmsg(TINFO, "bread <%d>", bread);
		dmsg(TINFO, "BUF: <%s>", buf);
		if (bread > 5)
		{
			if (!strcmp(buf, "Server refused our key"))
			{
				dmsg(TERR, "Server refused our key");
			}
		}
	}
        CloseHandle(wr_stderr);
	CloseHandle(pi.hProcess);

	return true;
}
0
jeep (6)
12/24/2008 4:08:02 AM
vc.mfc 33608 articles. 0 followers. Follow

0 Replies
2282 Views

Similar Articles

[PageSpeed] 47

Reply:

Similar Artilces:

Outbound Mail has stopped working
Why would outbound mail all of the sudden stopped working on a MS Exchange 2000 Server. ...

Message Size Limit, User Override not working
Hi I have a 10MB Message Size limit as default for Send/Recieve. I override some users to allow 25MB size. This is now within the last few weeks not working, messages are getting blocked. On some bounces the message is reading that the file size is over the limit of 25600K instead of Meg. Does anyone know of a bug that is causing this? My only solution so far is to remove the default limits and run unlimited. Not exactly what I want to do. "bensong69" <bensong69@discussions.microsoft.com> wrote in message news:54A2E698-D649-4007-9F67-8E44123297E7@microsoft.com... &g...

Report Writer output file for BACS
Need output file for NAT WEST / RBS Bankline. Any advise on "payment amount" formatting. Result needs to be 12n.2n Every else OK. Using (RW_Padzero - currency_string 12 2 2 ). Can't quite get formattting right. Any help appreciated. ...

Search doesn't work in one folder (Outlook 2003)
When the user has placed certain items in a separate folder, search can't find them. The messages are found when moved to another folder. The folder's name name is �M (non-ASCII) but renaming the folder doesn't help. ...

formula fill not working correctly in 2007
If I use the fill handle to copy a formula, the formulas are well copied, but the results are not. Exemple: The formula in A3 is =A1+A2. If I copy the formula to B3 it reads =B1+B2, which is correct. The result given in B3 however is not B1+B2 but the same result as in A3. I have to recalculate the formule in B3 for the correct result. In previous versions Excel did this automatically. How can I fix this problem or is it a bug? Hi It sounds as though calculation is set to Manual. Tools>Options>Calculation>and select Automatic -- Regards Roger Govier "Jante" <J...

Images and links don't work
I’ve published a site using MS Publisher to build it and FileZilla to publish it. The problem I have is that the images / pictures don’t appear and the links to other pages in the site don’t work. I understand that the HTML coding for these objects are not correct...for instance: The site name is http://stdb.eu and the HTML coding for an image is http://stdb.eu/images_file/image234. I need to rename it to read http://stdb.eu/image234 but don’t know how to do it...any suggestions? Many thanks Rooster UK Go here news://msnews.microsoft.com/microsoft.public.publisher.webdesign -- ...

Append Query Not Working 05-03-10
My Append query is not working and i am not sure why... Here is my SQL INSERT INTO tblContractPOTracking ( TrackingID ) SELECT tblDocTracking.TrackingID FROM tblDocTracking WHERE (((tblDocTracking.DocumentNumber)="5" Or (tblDocTracking.DocumentNumber)="6" Or (tblDocTracking.DocumentNumber)="7")); Please help! "not working" is a bit vague ... If you want more specific suggestions, please provide more specific description... Regards Jeff Boyce Microsoft Access MVP -- Disclaimer: This author may have received products and s...

No Group dialog box appear when working in Pivot Table
I'm trying to group a range of dates in pivot table. According to help files a dialog box should appear when selecting Group..., but nothing happens except a grouping of the entire marked range. How do I go about in order to make the Grouping dialog box show? Best Regards PerD > PerD, This might be something particular to my set-up (XL2K), but I have to build the table initially by specifying the data range *exactly* (click'n'drag on the worksheet) for grouping dates to be an option. If I use a blanket source (eg: A:B) it won't cut it. Try it again from scratch, the...

not between operator not working
Hi, I am trying to query my data and I want to exclude a whole bunch of values. However when I use not between x and y, it still includes it. I am using MS Access 2007 Any idea? -- Have a nice day Show us the SQL. Open the query in design view. Next go to View, SQL View and copy and past it here. Also some examples of the data that isn't being exluded. -- Jerry Whittle, Microsoft Access MVP Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder. "Cricri" wrote: > Hi, I am trying to query my data and I want to exclude a whole bunch of...

Emailmerge not working in Publisher
I'm using Publisher 2007 with the e-mail merge feature. In the email preview, all my records look fine. But when I send the e-mails, they contain the merge fields themselves <<name>> <<company name>> etc instead of the merged data. I have several merge fields inserted throughout my text box. The only way I got anything to work correctly is to limit it to one merge field early in a small, separate text box. But I want to insert other merge fields throughout my document. I am using Outlook 2007, however I have a specific list created for the merge so fields are not be...

To ensure the working of SSRS
How to ensure that the reporting service is working fine in a machine, which is installed with SQL server 2005? Submitted via EggHeadCafe - Software Developer Portal of Choice Dr. Dotnetsky's Cool .NET Tips & Tricks #1 http://www.eggheadcafe.com/tutorials/aspnet/9aade63c-be0f-4fe5-a562-9f2750db35bc/dr-dotnetskys-cool-net.aspx Go to http://yourservername/Reports/Pages/Folder.aspx Even before you have deployed reports you should see the empty portal. If you are in the local administrators group on the machine you will see a contents tab, new folder, new data source etc. ...

Filter option not working
Unable to get the filter option to work after selecting 'Protect and Share Worksheet Have completed all the steps in relation to Format - Cells, but even though the cells are not locked the filter option can not be use How can I get this to work? Hi gianni While you are protecting the Sheet Tools>Protection>Protect Sheet Below are the rights that you can allow/Disallow all users. Check "Use Auto Filter" regards >-----Original Message----- >Unable to get the filter option to work after selecting 'Protect and Share Worksheet' >Have completed all the s...

NAI Spamkiller not Working
Hi We have installed NAI Spamkiller trial on our Groupshield / Exchange 2k3 server. The policy is configured on the gateway but does not even forward the basic spam keywords into the users junkmail folder. We have IMF installed, would this be the problem? Any help would be much appreciated. Thanks B On Sun, 19 Feb 2006 13:03:26 -0000, "Ben" <Ben@Newsgroups.microsoft.com> wrote: >Hi > >We have installed NAI Spamkiller trial on our Groupshield / Exchange 2k3 >server. > >The policy is configured on the gateway but does not even forward the basic &...

Resource Work Load
Hi there Can anyone help? I have a single master plan with a number of different projects in it. The same resources are working on all the projects. In the resource usage view I want see how many days each resource is working on a particular project on a monthly basis. So for example I want to see: HR May June July Joe Bloggs 15d 10d 12d Marketing May June July Joe Bloggs 5d 3d 4d In the Gantt chart view I added a text1 field with the project name and then tried to filter it in the resource usage view but it doesn�t display in the resource usage view Hope this ma...

I can't publish my work
i am done with my project at publishe and everything is ok. I click on publish to the web.. and a folder and internet explorer pgere are created. i have a space at geocities and i uploaded everything but a few images like the backgroung are missing and i have done it againg and againg but the same. can someone help me? You must not be uploading the contents of the folder. Refer to the FAQ http://www.publishermvps.com/Default.aspx?tabid=30 and the web design 2003 page at http://www.publishermvps.com David Bartosik - [MSFT MVP] www.publishermvps.com www.davidbartosik.com "Rye"...

CreateProcess question
Hi, I am trying to write an application that will launch a second application using CreateProcess... SECURITY_ATTRIBUTES sa; STARTUPINFO si; PROCESS_INFORMATION pi; ::ZeroMemory( &sa, sizeof(sa) ); sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; ::ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ::ZeroMemory( &pi, sizeof(pi) ); // Start the child process. if ( !CreateProcess( NULL, "C:\\second_app.exe", &sa, &sa, TRUE, 0, NULL, "C:\\", &si, &pi ) ) { return; } ...

"Show Placeholder" feature in options/view doesnt work
I have a macro that places a large number of pictures on a spreadsheet. I would like the pictures to show as "placeholders" to speed up viewing/editing. The only problem is that this feature (under Tools/Options/View) does not work. All the images are being display normally. I have tried this in Excel 2000/2003/XP with the same result. This feature works great in MS Word. Please help. To see what I'm talking about. Go to Tools/Options/View and check the "Show Placeholders" option. Now insert a picture or clipart. The image will be displayed normally instead of just a b...

Same setting not working
I have two accounts, mine (admin), and a guest account. I set up a mail account on the admin and it works fine, retrieves the mail from the comcast servers to my inbox, on start up. But if I set it up the same way on the guest account, it doesn't work at all, nothing is retrieved and it can't be viewed. Why is the guest account not working? Anyone? >-----Original Message----- >I have two accounts, mine (admin), and a guest account. I >set up a mail account on the admin and it works fine, >retrieves the mail from the comcast servers to my inbox, >on start up. B...

Add expiration date to work orders and quotes
Anyone know of a way to add the expiration date to work orders and quptes? Thanks, Nick Use the variable Transaction.OrderDueDate Here is an example: <IF> <CONDITION> (Transaction.Type = TransactionLayaway) </CONDITION> <THEN> <ROW> "Expires: " Transaction.OrderDueDate "|" </ROW> </THEN> </IF> <IF> <CONDITION> (Transaction.Type = TransactionBackorder) </CONDITION> <THEN> ...

GDI is a "Top 50" Inc500 Listed Company...Are You Tired of Working Hard to Make Someone Else Rich?
Dear Friends, Are You Tired of Working Hard to Make Someone Else Rich? This Inc500 listed company is giving away money... This company is going to set me up for life and it can do the same for you. Read about how 1000's of real people worldwide who are building their own "Income for Life"=99 http://freedom.ws/helenmoonlight/show_dvd Watch the video until the end - make sure your speakers are on before you click http://www.website.ws/helenmoonlight I am confident that you will be impressed with what you see and hear. http://www.my.ws/helenmoonligh...

Security group doesn't work on Exchange Mailbox permissions
We're running SBS 2003. I am trying to give a group of users access to a couple of general purpose Exchange mailboxes. I can give the users access by adding their accounts individually to the Mailbox in question. (Exchange Advanced / Mailbox Rights / Full Access) This works fine and they can open the Mailbox in Outlook. However, when I try to do this using a Universal Security group, it doesn't work. We get an "Unable to Display Folder. Microsoft Outlook could not access the specified folder location." This is what I've done... Assume I want people accessing the ...

Code completion not working in VC++ 6.0
Hi, Anyone seen this before? Code completion is not working properly in visual C++ 6.0. When I type . or ->, I no longer see the member list after it. Once I type in a function and ( then it will show me the parameters. But not the member list. I checked and I do have all the code completion options selected. What gives? Not sure when this stopped working, I haven't used it in quite some time (probably a couple years!) but now am using it again and this is driving me nuts. Am thinking maybe I should reinstall but would like to avoid that (especially since who knows if it will e...

URL/Hyperlink not working for recipients
I am using Outlook 2003 running on Windows XP in a Windows 2003 Server environment. I administer an application that requires the user to install the program from a .bat file. I send our users an e-mail with a URL to the bat file (e.g. \\server123 \Application\install.bat). The URL cannot launch the bat file and search Locate Link Browser dialog opens instead. The work around is to cut and paste the URL into the Start\Run dialog where it works fine. (I think this implies that the UNC is defined properly.) Also, the hand icon displays properly when the user rolls the mouse over t...

how to load/import/populate an existing works database
Hi, I want to put a flat file (.txt) file into an existing works 7.0 database. I can "open" the file, but it doesnt have any column names for the data (delimited by commas or tabs). How do I get this data loaded into an "Existing" database.. Does everyone key all data into works databases? Is there no provision to load in a "batch" style. I have the database defiled, with the correect columns, but when I "open" the txt file, it puts it into a New unnamed database rather than the one I want it to go into. Can I then some how "merge" thi...

Adventure Works licenses question
Hi all, My company is using the Adventure Works Cycle MSDN license for testing purpose. We also bought the full Suite Pro license with about 25 users to be put on the prod environment. My question is: is it possible to extend the number of users (from the initial 15) in the Adventure Works Cycle test platform? Thanks Eric Only if your actual company name happens to be Adventure Works Cycle The key is specific to the exact company name, capitalisation included "Eric" <NOSPAMerich742001@yahoo.fr> wrote in message news:OjjGD0LTFHA.2520@TK2MSFTNGP09.phx.gbl... > H...