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
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.

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

	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.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,
		dmsg(TERR, "PeekNamedPipe stderr");
		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");

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

0 Replies

Similar Articles

[PageSpeed] 9


Similar Artilces:

Trying to make part of an output in another cell italicized.
Hello all, I have Excel from Office XP and am using it on Windows XP Home Edition I'm working on a program where users enter text in various cells. Fo example: A B 1 Name: ------ 2 Date: ------ Then the text that they enter is displayed in another cell all togethe using the following formula: =$B$4&", "&$B$5&". "&"("&$B$6&"). "&$B$7&". "&$B$8&" "&$B$9&"("&$B$10&"), "&$B$11&"-"&$B$12&"." I'...

Running a PIF file using CreateProcess in an allocated console window
Hello, I am trying to find a way to execute a pif file within the context of my own application's console using AllocConsole. My basic need is to have the console in my context so I can use the console API's AND I must use the pif parameters for EMS, XMS, and a few other parameters. Is there a way to do this ? Is there a way around ? For example, try running "start /b XX.pif" I am getting an error message The NTVDM CPU has encountered an illegal instruction. and get the Close Ignore buttons. This is not related to any problems in the DOS application. If I use CREATE_...

Out of office not working #6
Hi sbs 2003 standard with exchange 2003. One of the users does not have his out of office working. Have removed all rules and reinstalled Outlook but still no luck. What can I do to try to fix it form here? Many Thanks Regards Have you tried deleting and recreating the Outlook profile? Can the OOF be set using OWA? "John" <> wrote in message news:%23v1xSeT2JHA.1096@TK2MSFTNGP06.phx.gbl... > Hi > > sbs 2003 standard with exchange 2003. One of the users does not have his out > of office working. Have removed all rules and reinstalled...

Strange Output
Hello, everybody !!! Why this fragment of code shows : ac cout<<"a\??/??/bc"; Thanks All !!! "Alex Dmitriev" <> wrote in message news:ecTgPp8pEHA.3800@TK2MSFTNGP14.phx.gbl... > Hello, everybody !!! > Why this fragment of code shows : ac > > cout<<"a\??/??/bc"; '??/' is a '\' so you end up with "a\\\bc"

visual studio 6 output window addon
Hi, I am using visual studio 6 and have written a small perl script to check that there are no conflicting resources in my resource.h file. The script works fine, and when there is an error message, it reports so in the output window. However, i'm hoping to take it one step further and so when i click on the error message, it takes me to the correct line of the offending file. Is there anyway of achieving this functionality in Visual Studio 6? Since compiler warning messages have this, i thought there may have been a way that custome scripts could have it to. Thanks in advance, Brett. ...

Windows in Taskbar
Hi, I have multiple Excel worksheets open and I like to ALT+TAB between them. This was all fine until recently when it no longer shows the workbooks in the taskbar. The option "Windows in Taskbar" is checked. I've tried unchecking it, closing Excel, re starting Excel and selecting the option again, but it does nothing. I'm using Excel with Office 2003. I checked MS Word 2003 and this works fine with the multiple documents in the task bar, only Excel is behaving strange. Can anyone help? Regards, Paul. Paul The only thing I can find in the kb is, an ongoing problem wit...

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; } ...

Conditional Formatting Not Working Consistently
One of our Excel users is applying conditional formatting on cells within a worksheet that are linked to other worksheets in the same file and he is getting inconsistent results i.e., sometimes it applies the formatting and other times it won't. He seems to have the problem primarily when he selects a range within a column and then applies the conditional formatting. The conditional formatting statement applied to cell C5 is: Formula is =$B$5-$C$5=0 then format as red and bold. He is concerned about the ability to rely on this feature working properly. Since he is our Accounting Man...

Working with Sets
Are there any pre-defined workbook functions that deal with sets? For example, finding if a particular value/token is member of a set (array or selection), what values are present in the intersection or union of multiple sets, etc. These things can be done with the Find and Match functions together with logical operators, but it messy. TIA. -- Jay. (remove dashes for legal email address) ...

Starting an MFC application with CreateProcess Api
Hi all, I am trying to start a dialog based MFC application using CreateProcess Api. Also my MFC application takes a single command line argument from CreateProcess Api. MFC Code within the InitInstance BOOL CDispatchApp::InitInstance() { CString cmd; cmd = m_lpCmdLine; CDispatchDlg dlg; m_pMainWnd = &dlg; dlg.command = cmd; INT_PTR nResponse = dlg.DoModal(); } and then within the CDispatchDlg class i am using this command line argument Now this works fine if i start my application from command prompt. But when i start my application using CreateProcess Api, argument does...

SBS2K3 connect computer site not working
After installing CRM, when I navigate to http://servername/exchange or http://servername/connectcomputer; they are not working page can't be displayed or it ask for some user and passwork authentication. However, when i navigate to http://servername the CRM comes up. Any suggestions on whats going on? TIA I have had tone of problem with the google Tool bar when I uninstalled it or turned off the pop up blocker just about everything works fine. Not to sure if it's installed or not but I did find that issue Good luck TOM >-----Original Message----- >After installing CRM...

Working in Sheet2 with data from Sheet1
I am working in Sheet2. The data is in Sheet1. I can not get the data in column in the 15th column to initalize the "If" even if Textbox1.Text matches. For k= 1 to 100 If Sheets("Sheet1").Cells(k,15)=TextBox1.Text Then code... End if Next k I tried: If Sheets("Sheet1").Cells(k,15)=Sheets("Sheet2").TextBox1.Text Then With Sheets("Sheet2") If Sheets("Sheet1").Cells(k,15)=.TextBox1.Text Then .... End With If Sheets("Sheet1").Cells(k,15)=TextBox1.Text Then Nothing worked. Philos...

Must use updatetable query
I want to set SNumber field of Table01 using a concatenation of two fields Fsn and AllFsn from Table03. Fsn link these two tables, below is my query however I'm getting a Must use updatetable query. Any work around on this? UPDATE Table1 set SNumber = (SELECT Fsn & AllFsn FROM Table03 WHERE Table1. Fsn = Table03.Fsn) Thanks, -- spread the WORD Message posted via Try this -- UPDATE [Table1] INNER JOIN [Table03] ON [Table1].[Fsn] = [Table03].[Fsn] SET [Table1].[SNumber] = [Table03].[Fsn]&[Table03].[AllFsn]; Or try it with two ...

VISTA UAC problem with ActiveX using CreateProcess
Hi group, I have a VC6 ActiveX which uses CreateProcess to run an executable it downloaded. All works well on XP. On Vista with explorer, the Activex installs and registers fine, download the file but vista blocks the CreateProcess. GetLastError returns 'Access is denied'. Can anyone help me so this problem ? Is the right solution to add a manifest to the ActiveX ? will it work also for an ActiveX launched from explorer ? Do I need to modify only the ActiveX or also the process it is starting ? Can I solve this without recompiling the ActiveX under a higher compiler than VC6 ? Than...

automating outputting reports using Office Document Image Writer
Greetings -- I'm working on a management reporting database, where I'll need to generate a slate of reports every week. We output reports using the Document Image Writer as MDI files for distribution. The quantity of reports is significant, and the time to run them is also significant. Would like to mechanize generating these reports, so I don't have to babysit the computer as much. Is there a way to output a report to the image writer, and pass it a parameter for the file name to save the report under? I've looked at DoCmd.PrintOut and DoCmd.OpenReport, and haven&...

REmote Display not working using win ce6.0
Hi am vinoth am right now trying to connect the remote display in my pc. i am using omapL138 EVM kit with win ce6.0. i can able to do all the things only i cant able to see my device when i run cerdisp or cerhost. i cant unable to solve or find the problem. am using kitl as transport and server.i can able to attach the device.i can get the bin image. Thanks Vinoth. -- vinoth Message posted via On 5/14/2010 6:54 AM, vinoth006 via wrote: > Hi > am vinoth am right...

AutoComplete works sometimes but not others
Entering the same word will kick in AutoComplete sometimes but not others. The word typed the same way exactly. For example lets say I already have these 3 words ALREADY entered in 3 different cells but in the same column and they are the only words in my spreadsheet beginning with the 2 letters Ne: Netflix New Rochelle Neophyte If I begin to type in another cell of this same column (don't really think which column should matter) like this: Net (Autocomplete should now kick in by adding flix) or if I type in: new (Autocomplete should now kick in by adding Rochelle (space followed...

Output to screen width to default to certain width and breadth
Output to screen width to default to certain width and breadth ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane.

Outlook 2007 Rule does not work
I am trying to create a rule where I can filer e-mails from Blockbuster and move them to the "blockbuster" folder. I have three other rules that do the almost the same. No matter how I setup the rule outlook seems to only copy the e-mail and not move it. The other rules I have setup (and function fine) simply move e-mail messages sent to a specific account and move such messages to a folder of my choosing. Here, all I want to do is move messages from a sender to a folder and I can't get it to work. I have been told to add the "stop processing more messages" ...

How to save query output as a table??
What I would like to do is run a query, but then save the query output as a new table. I can work out how to save the query, but not the result How do I do this please? Thanks -- John Perry John Perry wrote: > What I would like to do is run a query, but then save the query output > as a new table. I can work out how to save the query, but not the > result > > How do I do this please? Make the query into a Make Table query or use it as the input to a Make Table query. If you press the "Query" item in the menu ...

CFileDialog, CreateProcess, and Windows XP
I'm having some strange behavior tied to CFileDialog and CreateProcess running under Windows XP and was hoping for any insight or leads to help sort it out. I have two seperate applications written in Visual C++ 6.0 using MFC and running under Windows XP. App1 uses CFileDialog to gain access to some files and behaves just fine when App1 is executed seperately. The CFileDialog window defaults to List view and the user can change the file view (to Detail, Thumbnail, etc). It also uses some extension filters and when the user selects a filter, only those files with the correct extension...

Outlook Client - Mapping
Hi all, could anybody explain to me how Outlook &/or MS CRM 3.0 identifies the fields that are mapped please? I'm working on an Outlook Client implementation and will have to include extra fields in the synchronization. I've seen the post on how to show the Parent Account field, but need more info on how Outlook knows that FIELD X = FIELD Y in MS CRM (or the other way around)... The other problem we've come across is that a lot of our customised fields have an underscore in them (ie: PREFIX_FIELDNAME, with the prefix denoting that it's a custo). however, when I try ...

CreateProcess #2
I'm attempting to create a process that runs an echo command and pipes it to another application. I can run the application, but I can't run the echo command. Here's the code that is failing: BOOL rVal = TRUE; int err = 0; PROCESS_INFORMATION pi; STARTUPINFO si; err = GetLastError(); memset( &pi, 0, sizeof(PROCESS_INFORMATION) ); memset(&si, 0, sizeof(STARTUPINFO)); si.cb= sizeof(STARTUPINFO); si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; si.lpDesktop = ""; rVal = CreateProcess("echo", NULL...

OWA not working #6
I have an issues with a Exchange 2003 server. I cannot get to OWA. The server crashed (lost 2 drives on a RAID 5) and the person who 'recovered' the system seem to have installed Exchange on the d:\ drive instead of the c:\ drive where I think it was originally installed (I don't see the Exchange server on the c:\ at all) I found KB article: 896742 and it describes the problem precisly. I ran the Security Configuration Wizard and udpated the location of the following services. . EMicrosoft Exchange MTA Stacks (Emsmta.exe) . Microsoft Exchange Information Store (...

Mapping dataset tables to XML output
Hi, I'm really stuck with this one. I have a dataset with two tables. One table is company data, and the other is contacts. I populate these by using a SP in SQL Server which returns the two tables in one call. I'm using Microsoft EnterpriseLibrary for Data to get the data from SP. It works fine and I get two tables in the dataset, "Table1" and "Table2". I then have an XML-file, which will serve as a template to generate the XML-schema, which I load into the dataset with the InferXmlSchema method. This gives me a perfectly good looking XML-Schema of how I w...