Click here to Skip to main content
15,896,063 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: how to use createprocess to create a new console window(cmd.exe) and run commands Pin
Randor 9-Nov-09 7:17
professional Randor 9-Nov-09 7:17 
GeneralRe: how to use createprocess to create a new console window(cmd.exe) and run commands Pin
devgo9-Nov-09 7:28
devgo9-Nov-09 7:28 
QuestionRe: how to use createprocess to create a new console window(cmd.exe) and run commands Pin
David Crow9-Nov-09 7:52
David Crow9-Nov-09 7:52 
GeneralRe: how to use createprocess to create a new console window(cmd.exe) and run commands Pin
Randor 9-Nov-09 7:54
professional Randor 9-Nov-09 7:54 
GeneralRe: how to use createprocess to create a new console window(cmd.exe) and run commands Pin
devgo9-Nov-09 9:18
devgo9-Nov-09 9:18 
GeneralRe: how to use createprocess to create a new console window(cmd.exe) and run commands Pin
Randor 9-Nov-09 10:19
professional Randor 9-Nov-09 10:19 
GeneralRe: how to use createprocess to create a new console window(cmd.exe) and run commands Pin
devgo9-Nov-09 10:56
devgo9-Nov-09 10:56 
GeneralRe: how to use createprocess to create a new console window(cmd.exe) and run commands Pin
devgo11-Nov-09 9:15
devgo11-Nov-09 9:15 
Hi David,

As you were aware, i am trying to execute a command in the console window created through createprocess(); now i am trying to execute the command by using Pipes as you suggested.

I am pasting the code here. i am not able to print the string on the console window created. could you please suggest what i am doing wrong.

/********************************CODE ******************************* /
void main()
{

STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD i;
HANDLE hout;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
HWND hWnd = NULL;
TCHAR buf[128];
HANDLE g_hChildStd_IN_Rd = NULL;
HANDLE g_hChildStd_IN_Wr = NULL;
HANDLE g_hChildStd_OUT_Rd = NULL;
HANDLE g_hChildStd_OUT_Wr = NULL;
SECURITY_ATTRIBUTES saAttr;
DWORD dwRead, dwWritten;
CHAR chBuf[128];
BOOL bSuccess = FALSE;

// Set the bInheritHandle flag so pipe handles are inherited.

saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;

// Create a pipe for the child process's STDOUT.

if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0) )
printf("StdoutRd CreatePipe");

// Ensure the read handle to the pipe for STDOUT is not inherited.

if ( ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) )
printf("Stdout SetHandleInformation");

// Create a pipe for the child process's STDIN.
si.hStdError = g_hChildStd_OUT_Wr;
si.hStdOutput = g_hChildStd_OUT_Wr;
si.hStdInput = g_hChildStd_OUT_Rd;
//si.dwFlags |= STARTF_USESTDHANDLES;

// Start the child process.

if( !CreateProcess("C:\\windows\\system32\\cmd.exe", // No module name (use command line).
NULL,//// Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
CREATE_NEW_CONSOLE, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return;
}


bSuccess = WriteConsole(g_hChildStd_OUT_Rd, "dir", 3, &dwWritten, NULL);
CloseHandle(g_hChildStd_OUT_Rd);


/***********************************************************************************/
GeneralRe: how to use createprocess to create a new console window(cmd.exe) and run commands Pin
Randor 11-Nov-09 16:34
professional Randor 11-Nov-09 16:34 
QuestionIs there a way to register an activeX ocx file with relative path and not full path? Pin
eyal_balla9-Nov-09 4:31
eyal_balla9-Nov-09 4:31 
AnswerRe: Is there a way to register an activeX ocx file with relative path and not full path? Pin
Chris Losinger9-Nov-09 5:34
professionalChris Losinger9-Nov-09 5:34 
QuestionHow do I get contents of long strings in VS 2008 debugger? Pin
Interrobang9-Nov-09 4:28
Interrobang9-Nov-09 4:28 
AnswerRe: How do I get contents of long strings in VS 2008 debugger? Pin
loyal ginger9-Nov-09 4:48
loyal ginger9-Nov-09 4:48 
AnswerRe: How do I get contents of long strings in VS 2008 debugger? Pin
Chris Losinger9-Nov-09 4:50
professionalChris Losinger9-Nov-09 4:50 
QuestionSimple CToolTipCtrl trouble. Pin
Nikz29-Nov-09 4:20
Nikz29-Nov-09 4:20 
AnswerRe: Simple CToolTipCtrl trouble. Pin
Code-o-mat9-Nov-09 5:24
Code-o-mat9-Nov-09 5:24 
GeneralRe: Simple CToolTipCtrl trouble. Pin
Nikz29-Nov-09 5:52
Nikz29-Nov-09 5:52 
GeneralRe: Simple CToolTipCtrl trouble. Pin
Code-o-mat9-Nov-09 5:59
Code-o-mat9-Nov-09 5:59 
GeneralRe: Simple CToolTipCtrl trouble. Pin
Nikz29-Nov-09 6:13
Nikz29-Nov-09 6:13 
GeneralRe: Simple CToolTipCtrl trouble. Pin
Code-o-mat9-Nov-09 7:30
Code-o-mat9-Nov-09 7:30 
GeneralRe: Simple CToolTipCtrl trouble. Pin
Nikz29-Nov-09 10:48
Nikz29-Nov-09 10:48 
Question'c' Program [modified] Pin
singh.niraj40@yahoo.com9-Nov-09 4:01
singh.niraj40@yahoo.com9-Nov-09 4:01 
AnswerRe: 'c' Program Pin
Chris Losinger9-Nov-09 4:03
professionalChris Losinger9-Nov-09 4:03 
AnswerRe: 'c' Program Pin
David Crow9-Nov-09 4:21
David Crow9-Nov-09 4:21 
JokeRe: 'c' Program Pin
Cedric Moonen9-Nov-09 4:32
Cedric Moonen9-Nov-09 4:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.