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
2289 Views

Similar Articles

[PageSpeed] 58

Reply:

Similar Artilces:

Filter by form not working
When I use the filter by form option, I do the drop down arrows, but I see only the values Null, and NOT NULL, whereas the text says I should see a list of items in that column. Why I am not getting it? Thanks "Milind" <Milind@discussions.microsoft.com> wrote in message news:C3E22142-B57A-4246-8488-2E38F3C773F2@microsoft.com... > When I use the filter by form option, I do the drop down arrows, but I see > only the values Null, and NOT NULL, whereas the text says I should see a list > of items in that column. Why I am not getting it? Thanks If the number of distin...

How to tell microsoft that Excel Union Operator doesn't always work
What is the best way to report a bug to microsoft? Cell A1 through F1 contain the colors red, blue, green, yellow, pink, purple Cell a2 contains green Cell b2 contains =or(a2=(a1:f1)) as a control shift enter array formula. Cell c2 contains =or(a2 = (a1:b1,d1:f1)) CSE Cell b2 works fine, but cell c2 does not work. Seems to me that the Union operator (which is a ,) should work but does not. "UncleBob" <UncleBob@microsoft.com> schreef in bericht news:Ox4vAj1PEHA.2236@TK2MSFTNGP10.phx.gbl... > What is the best way to report a bug to microsoft? > > Cell A1 th...

hyperlinks in outlook 2003 do not work
Hi. Since installing Outlook 2003, I cannot link to sites that have the address in the emails. None of the "Link" buttons work. I have tried "Resetting Web settings" & look at the info that "Sue" from Mircosoft has given, but to no avail. I click on a link & a box comes up saying "Locate Web browser". I have also installed MYOB Accounting & cannot even open that. Can someone help. This is SOOOOOOO frustratiiong, as I tried to update to make it easier (Costs big $$) & all I am getting is a headache! Regards, Rob J When it says '...

custom filter does not work correctly
I have a worksheet with one column contains a list of codes in each cell. The list can be longer than 256 characters. When I tried to use the custom filter to filter this column, it does not seem to display rows containing what I was looking for correctly. In the column, the codes is listed in a comma delimited list like aaa, bbb, ccc, ... If I tried to use the custom filter to look for a code that exists on some rows beyond 256 characters, Excel will not display these rows. Only rows that the code can be found in the first 256 characters will be filtered. Is this a limitation of Excel...

Works Publisher 2000 to Office Publisher 2003
My old computer had the P2000, I now have the 2003. The P2003 is not recognizing my 2000 files. How do I correct this. Ditto for Works "generic" database to Office Access 2003 You mention Works which makes me wonder if you are thinking that Home Publishing is the same thing as Publisher. It isn't. Could this be the problem? -- JoAnn Paules MVP Microsoft [Publisher] "Tutu" <Tutu@discussions.microsoft.com> wrote in message news:A4BA0555-0DB4-42F2-B8C2-F0F08F29999A@microsoft.com... > My old computer had the P2000, I now have the 2003. The P2003 is no...

Out of Office Assistant Auto Reply not working
The out of office assistant does not send a note to anyone outside of my network. Using Outlook 2000 with Exchange Server. Auto Reply is sent to anyone that is local on my network but does not send outside. Any suggestions? Automatic replies to the internet are disabled by default in Exchange 5.5 and later. Check wth your Exchange administrator to see if he/she is willing to change this. -- Jocelyn Fiorello MVP - Outlook *** Messages sent to my e-mail address will NOT be answered -- please reply only to the newsgroup to preserve the message thread. *** In news:0a6f01c3d3b4$300761b...

Archiving not working properly.
New to this Outlook stuff so be gentle... Partner has Outlook 2000 a/c which is getting slow and beginning to lock up, presumably through a lack of attention to archiving. I understood that the main pst could be up to 2gig in this version but am not sure if, when the user also has the archive folders showing in the folder list, the size of the archive pst has to be included in an overall 2gig 'working margin'. I ask this, because when I tried to 'shave the inbox' a year at a time say, I found that the archive.pst only filled up to 738695, and then seemed to stick even ...

Lookup function doesn't work
I am using a lookup function to compare the results in sheet1 column 1 to sheet2 column 2 and return the results of sheet2 column2. The function seems to work for the first few entries, but then returns the wrong results for some of the other entries. I am using "=LOOKUP(A7,Sheet2!$A$2:$A$16,Sheet2!$B$2:$B$16)" and it is copied down a column of text/numeric entries in the first sheet. Has anyone else had problems with this? Thanks. -- Frank L Are the values in the lookup_vector i.e. "Sheet2!$A$2:$A$16" in ascending order ? -- Rgds Max xl 97 -- Please respond, in new...

Working With Charts
I have created "Cash Withdrawal" as a payee to account for ATM cash withdrawals from my checking account. I am able to call up a report about this "payee" in the Reports Gallery. But I am unable to customize the report and make it a chart. How can I make a line chart of my cash withdrawals? Line Chart is not an option for the Payee Spending report. You can, however, use the Account transactions report to create a line chart and only the select the one payee. "David Lingenfelter" <anonymous@discussions.microsoft.com> wrote in message news:06d401c39d0d...

execute method doesnt work
I have two Custom webpages both of them uses Current user information to get details about their opportunity. Both of them using Following code. One of the page works fine but otherone does nt. I dont know whats wrong with the second page. The code that it is using is below. service = new CrmService(); service.Url = "http://<server>:5555/mscrmservices/2006/crmservice.asmx" service.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; WhoAmIRequest userRequest = new WhoAmIRequest(); WhoAmIResponse user = (WhoAmIResponse)service.Execute(userRequest); on...

Outlook Connector Not Working
Getting the following error.. Have de-installed/re-installed both the connector and outlook a couple of times...any suggestions... Application Name: OUTLOOK.EXE Application Version: 12.0.4518.1014 Application Timestamp: 4542840f Fault Module Name: StackHash_942c Fault Module Version: 6.1.7600.16385 Fault Module Timestamp: 4a5bdb3b Exception Code: c0000374 Exception Offset: 000cdcbb OS Version: 6.1.7600.2.0.0.768.3 Locale ID: 1033 Additional Information 1: 942c Additional Information 2: 942c67ae768f62718e8b8755256a5a74 Additional Information 3: be05 ...

Working time and days
I would like to be able to caculate working time when the cell format is 4/1/2005 6:40:26 AM (not seperated into date and time) Cell A1 dd/mm/yyyy h:mm:ss (First Day) Cell A2 dd/mm/yyyy h:mm:ss (Last day) Working hours would be 8:00 to 17:00 Public holidays need to be taken out too The result should be working days hours and minutes or just hours and minutes, so that Saturday, Sunday, public holidays & between the hours of 17:00 to 8:00 to the next working day would not count. I've tried using: =((NETWORKDAYS(A1,C1)-2)*9)/24+TIME(17,00,0)-B1+D1-TIME(8,00,0) But I think this ...

Vlookup not working to merge workbooks?
HI, I have 8 workbooks, each with one work sheet containing an identical column A then the next three columns in each contain unique data that I want to combine from all 8 based on column A. I'm using the following formula: =VLOOKUP($A1,'A2 AlleleReport.XLS'!$A$1:$D$100,1,TRUE) Although I've opened and linked all the files using connections it doesn't seem to be working? Initially Excel opens up a box for me to browse where the linked file is (once I've put the formula in the first workbook), I click it, but then it refers to $A$1 of my 1st workbook t...

With start-up my printer automatically re-prints all work. Why?
I have a new OKI B63000 printer and every morning with Windows Start-Up, my printer automatically re-prints all my day's work, needlessly wasting a lot of paper and toner. I imagine there is a command somewhere for this. How can I stop it? Might look in scheduled tasks. How To Schedule Tasks in Windows XP http://support.microsoft.com/kb/308569/en-us -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Andry C" <Andry C@discussions.microsoft.com> wrote in message news:D092C731-CE6D-403A-B7B3-6C3C57C2F92D@microsoft....

Resolution & Size output options
When I use Save As on an object and select any of the bitmap formats (bmp, jpg, gif), I am given an Output Options panel. At the bottom of that panel, there are two options: Resolution and Size. Both of them offer the same suboptions: Screen, Printer, Source, and Custom. The Custom suboption also has a pair of dimensions. These dimensions are changed by selecting the Screen, Printer, & Source suboptions, but greyed out. Can someone explain exactly what these options do? I have 2 objects in a Visio document. One was cut-and-pasted from a musical notation program via the clipboard usi...

vlookup not working (active)
I have a random problem with vlookup that I've not been able to figure out. Sometimes when I try to lookup a value on a different workbook using vlookup, the formula disappears when I swich to the other workbook. I'm wondering if this has something to do with the format that the workbooks are save in. To work around this problem I end up having to copy the worksheet from the other workbook and paste it into the workbook I'm doing the vlookup in. This works, but is rather annoying. What causes this problem, and what's the solution? If the =vlookup() formula disappea...

Why does this not work (selecting a date) ?
SELECT CDate((Month(RecordDate) & '/' & Day(RecordDate) & '/' & Year(RecordDate)) AS RecDate This converts 8/31/2007 to 8/1/2007 Works fine for me with 2003 SP2. You omitted a closing parenthesis. -- KARL DEWEY Build a little - Test a little "mscertified" wrote: > SELECT CDate((Month(RecordDate) & '/' & Day(RecordDate) & '/' & > Year(RecordDate)) AS RecDate > > This converts 8/31/2007 to 8/1/2007 Where is the missing parentheses? I count 4 opening and 4 closing??? "KARL DEWEY" wrote: >...

Cross-Reference Dialog Box No Longer Works Right
This is a change in Word 2007 from previous versions, and it's starting to drive me crazy. I often insert a cross reference to a "numbered item" - normally a heading. You can do with keystroke shortcuts or by clicing "Cross-reference" in the "References" toolbar. The problem is with the little dialog box that pops up at this point. Its main window shows, in outline form, all the headings in the document, and I then pick the one to which I want to insert a reference. Except ... it doesn't. The main window in the dialog box OMITS all the ...

Inserted Controls do not work once Saved
I am creating a form with textbox controls and date control. They work fine until I save the document then the controls seem to disappear. Has anyone had this problem before and what is the solution? I have copied the form and re-created the controls, but once again upon saving the form the controls go away. HELP Which version of Word are you using? Note that if you are using Word 2007, inserting content controls, and then saving in Word 97-2003 format, content controls will be converted to static text. -- Stefan Blom Microsoft Word MVP "LRay67" <...

Query Output
Help, I am working with make table queries. I have a A make table query and a B make table query each with various information that the query has preformed. I am trying to get the following output into a text file. A Make Table Information B Make Table Information A Make Table Information B Make Table Information etc. There are over 300 items in each table. Each A Corresponds with a B. I need to keep the 2 records separate for where i have to upload them. I tried having a common identifier for the two tables and creating a big query with all the information on, but i ...

Why does rpc over https not work?
Hi all, When I configure the rpc over https on the exchange 2003 servers, I still can not make a connection as it pops me for the password. After I entered my domain password, it can not be accepted. We have FE and BE servers and exchange 2003 SP2. I configure s tje FE server to use basic authentication and integrated authentication on the backend serves. I can not figure out why it does not work. Can anyone help me with these? Hi, Try to access https://common-name/rpc. It should prompt you for user name and password. If it is giving the certificate warning, install the certific...

Sizing handles on my chart titles don't work!
I can SEE the sizing handles when I click on the text box, but when I run the mouse over them, I don't get the double-headed arrow. I can't resize the chart title, or either of the axis titles. Strangely, I CAN resize the legend box. I have tried re-making the chart through the Wizard - I've also tried other charts in other files. I can't resize any of the title boxes! Help! Select the chart title and change the font size. "Nicole" <Nicole@discussions.microsoft.com> wrote in message news:F57E90C1-F158-4EBA-8DFB-3E21888CAAA4@microsoft.com... >I can SEE...

IMF Message Filter has stopped working
Exchange 2003, IMF was installed and working fine until recently when the filter has just stopped working. All filters have been applied to the Virtual Server. There are no errors in the event log. There are no messages in the archive folder. I have re-started the information store but the problem remains. No changes had been made to IMF, it just stopped working. On Tue, 30 Aug 2005 10:39:59 +0100, "andrew.hinkin" <andrew.hinkin@akhter.co.uk> wrote: >Exchange 2003, IMF was installed and working fine until recently when the >filter has just stopped working. All f...

Zoom not working with wireless mouse and Windows 7
I installed Office 7 on a new system with Windows 7 and a Microsoft wireless laser mouse 6000 and the zoom won't work using the control key with the wheel on the mouse -- it works fine on my old XP system and with my adobe products on the new system -- is there a way to make the zoom work again? Have you installed the mouse drivers and checked to make sure that the button (and wheel) assignments in the mouse Properties are correct? -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "katluc" <katluc@discu...

Working out UK tax
ive set up a spreadsheet to calculate my income per week. I now would like to make my tax and national insurance boxes to be calculated automatically. meaning all im required to do is type in my hours worked for that week. The problem is finding a formula that can do this. The UK tax and national insurance is directly proportional to how much you earn. Not one fixed percentage. Let me show us some numbers: - Payslip 1 Total Pay = 297.62 Tax = 40.65 = 13.7% N.I = 22.73 = 7.6% Payslip 2 Total Pay = 242.63 Tax =...