Pipe from GUI app to console process
-
Hello everybody! I've been working for some hours in a project of a GUI app that runs a console app (ssh) in background. Well, I've been using many examples of code from here (codeproject) and from the internet, but I had aways stoped at the same error. Maybe someone can give me some help... here is what happens: I create the pipes and begin the execution of the program... everything goes fine, the ssh program ask for the password, and then I use WriteFile to send it the password. >Crash!< It continues the execution and do not even try to validate the password :sigh: I'll put some code here:
//creating pipes
if(!CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &secattr, 0))
AfxMessageBox("Error in pipe Out");SetHandleInformation(hChildStdoutRd, HANDLE_FLAG_INHERIT, 0);
if(!CreatePipe(&hChildStdinRd, &hChildStdinWr, &secattr, 0))
AfxMessageBox("Error in pipe In");SetHandleInformation(hChildStdinWr, HANDLE_FLAG_INHERIT, 0);
/////////////////////////////////////////////////////////////
// In another thread, I started the app. The pipes stay in a object that is
// passed through parameter to the thread execution.
STARTUPINFO sInfo;
ZeroMemory(&sInfo,sizeof(sInfo));
PROCESS_INFORMATION pInfo;
ZeroMemory(&pInfo,sizeof(pInfo));
sInfo.cb=sizeof(sInfo);
sInfo.dwFlags |= STARTF_USESTDHANDLES;
sInfo.hStdInput = cssh->hChildStdinRd;
sInfo.hStdOutput = cssh->hChildStdoutWr;
sInfo.hStdError = cssh->hChildStdoutWr;//In the same thread, I read the first line of execution...
CloseHandle(csftp->hChildStdoutWr);for( ;; ) {
if(!ReadFile(csftp->hChildStdoutRd, buf, 100, &dwRead, NULL) || dwRead == 0)
break;buf[dwRead] = '\0';
strAux = buf;
cssh->ShowText(strAux);
}// The password is typed in a Edit (for test porpouse only), and a try this code:
strcpy(strPass, szBuf);if(!WriteFile(hChildStdinWr, szBuf, strPass.GetLength() ,&dwWritten, NULL))
AfxMessageBox("Error in hChildStdinWr");if(!CloseHandle(hChildStdinWr))
AfxMessageBox("Error in hChildStdinWr");After execute the code above, the ssh app runs all the authentication with failure
user@host's password: user@host's password: user@host's password: user@host's password: user@host's password: Using username "user". Access denied Access denied Access denied Access denied Access denied Fatal: Server sent disconnect message type 2 (SSH_DISCONNECT_PROTOCOL_ERROR): "Too many authentication failures for user"
Any help, is welcome :) chee -
Hello everybody! I've been working for some hours in a project of a GUI app that runs a console app (ssh) in background. Well, I've been using many examples of code from here (codeproject) and from the internet, but I had aways stoped at the same error. Maybe someone can give me some help... here is what happens: I create the pipes and begin the execution of the program... everything goes fine, the ssh program ask for the password, and then I use WriteFile to send it the password. >Crash!< It continues the execution and do not even try to validate the password :sigh: I'll put some code here:
//creating pipes
if(!CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &secattr, 0))
AfxMessageBox("Error in pipe Out");SetHandleInformation(hChildStdoutRd, HANDLE_FLAG_INHERIT, 0);
if(!CreatePipe(&hChildStdinRd, &hChildStdinWr, &secattr, 0))
AfxMessageBox("Error in pipe In");SetHandleInformation(hChildStdinWr, HANDLE_FLAG_INHERIT, 0);
/////////////////////////////////////////////////////////////
// In another thread, I started the app. The pipes stay in a object that is
// passed through parameter to the thread execution.
STARTUPINFO sInfo;
ZeroMemory(&sInfo,sizeof(sInfo));
PROCESS_INFORMATION pInfo;
ZeroMemory(&pInfo,sizeof(pInfo));
sInfo.cb=sizeof(sInfo);
sInfo.dwFlags |= STARTF_USESTDHANDLES;
sInfo.hStdInput = cssh->hChildStdinRd;
sInfo.hStdOutput = cssh->hChildStdoutWr;
sInfo.hStdError = cssh->hChildStdoutWr;//In the same thread, I read the first line of execution...
CloseHandle(csftp->hChildStdoutWr);for( ;; ) {
if(!ReadFile(csftp->hChildStdoutRd, buf, 100, &dwRead, NULL) || dwRead == 0)
break;buf[dwRead] = '\0';
strAux = buf;
cssh->ShowText(strAux);
}// The password is typed in a Edit (for test porpouse only), and a try this code:
strcpy(strPass, szBuf);if(!WriteFile(hChildStdinWr, szBuf, strPass.GetLength() ,&dwWritten, NULL))
AfxMessageBox("Error in hChildStdinWr");if(!CloseHandle(hChildStdinWr))
AfxMessageBox("Error in hChildStdinWr");After execute the code above, the ssh app runs all the authentication with failure
user@host's password: user@host's password: user@host's password: user@host's password: user@host's password: Using username "user". Access denied Access denied Access denied Access denied Access denied Fatal: Server sent disconnect message type 2 (SSH_DISCONNECT_PROTOCOL_ERROR): "Too many authentication failures for user"
Any help, is welcome :) cheeHave you seen these two articles: http://support.microsoft.com/default.aspx?scid=kb;en-us;190351[^] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/creating_a_child_process_with_redirected_input_and_output.asp[^]
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
Have you seen these two articles: http://support.microsoft.com/default.aspx?scid=kb;en-us;190351[^] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/creating_a_child_process_with_redirected_input_and_output.asp[^]
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
Have you seen these two articles: http://support.microsoft.com/default.aspx?scid=kb;en-us;190351[^] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/creating_a_child_process_with_redirected_input_and_output.asp[^]
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
Hello everybody! I've been working for some hours in a project of a GUI app that runs a console app (ssh) in background. Well, I've been using many examples of code from here (codeproject) and from the internet, but I had aways stoped at the same error. Maybe someone can give me some help... here is what happens: I create the pipes and begin the execution of the program... everything goes fine, the ssh program ask for the password, and then I use WriteFile to send it the password. >Crash!< It continues the execution and do not even try to validate the password :sigh: I'll put some code here:
//creating pipes
if(!CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &secattr, 0))
AfxMessageBox("Error in pipe Out");SetHandleInformation(hChildStdoutRd, HANDLE_FLAG_INHERIT, 0);
if(!CreatePipe(&hChildStdinRd, &hChildStdinWr, &secattr, 0))
AfxMessageBox("Error in pipe In");SetHandleInformation(hChildStdinWr, HANDLE_FLAG_INHERIT, 0);
/////////////////////////////////////////////////////////////
// In another thread, I started the app. The pipes stay in a object that is
// passed through parameter to the thread execution.
STARTUPINFO sInfo;
ZeroMemory(&sInfo,sizeof(sInfo));
PROCESS_INFORMATION pInfo;
ZeroMemory(&pInfo,sizeof(pInfo));
sInfo.cb=sizeof(sInfo);
sInfo.dwFlags |= STARTF_USESTDHANDLES;
sInfo.hStdInput = cssh->hChildStdinRd;
sInfo.hStdOutput = cssh->hChildStdoutWr;
sInfo.hStdError = cssh->hChildStdoutWr;//In the same thread, I read the first line of execution...
CloseHandle(csftp->hChildStdoutWr);for( ;; ) {
if(!ReadFile(csftp->hChildStdoutRd, buf, 100, &dwRead, NULL) || dwRead == 0)
break;buf[dwRead] = '\0';
strAux = buf;
cssh->ShowText(strAux);
}// The password is typed in a Edit (for test porpouse only), and a try this code:
strcpy(strPass, szBuf);if(!WriteFile(hChildStdinWr, szBuf, strPass.GetLength() ,&dwWritten, NULL))
AfxMessageBox("Error in hChildStdinWr");if(!CloseHandle(hChildStdinWr))
AfxMessageBox("Error in hChildStdinWr");After execute the code above, the ssh app runs all the authentication with failure
user@host's password: user@host's password: user@host's password: user@host's password: user@host's password: Using username "user". Access denied Access denied Access denied Access denied Access denied Fatal: Server sent disconnect message type 2 (SSH_DISCONNECT_PROTOCOL_ERROR): "Too many authentication failures for user"
Any help, is welcome :) chee1)upload ur code somewhere, someone may download and test it for u. 2)u do need to study a sample carefully. at least, i don't think code like this meaningful: sInfo.hStdInput = cssh->hChildStdinRd; before u call CreatePipe() and CreateProcess()
A special image tool for C++ programmers, don't miss it! The world unique Software Label Maker is here for you and me ... A nice hyper tool for optimizing your MS html-help contents.