Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[c++] redirecting output

Featured Replies

trying to launch a separate executable and redirect the output to another file for parsing. ive looked in msdn and the sample they give doesn't seem to work with the environment i have. don't know if im missing something.

here is the code i have

int LaunchProcess(LPTSTR programName, LPTSTR commandLine, BOOL wait_flag, const _TCHAR *curDir = NULL, const _TCHAR *redirOut = NULL)
{
PROCESS_INFORMATION pi;
STARTUPINFO si;
DWORD dwExitCode = 0;
DWORD dw;
DWORD last_error;
BOOL fSuccess;
BOOL fExit;
DWORD create_flags;
HANDLE hFileout = NULL;
SECURITY_ATTRIBUTES saAttr;
int return_status;

ZeroMemory(&si, sizeof(STARTUPINFO));

if (redirOut != NULL)
{
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;

hFileout = CreateFile(redirOut
, FILE_WRITE_DATA
, FILE_SHARE_WRITE
, &saAttr //security attributes
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL);
if (!hFileout == INVALID_HANDLE_VALUE)
{
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdOutput = hFileout;
si.hStdError = hFileout;
}
}

if( wait_flag )
{
create_flags = 0;
}
else
{
create_flags = CREATE_NEW_CONSOLE;
}

// SETUP STARTUP INFORMATION STRUCTURE:
si.cb = sizeof(STARTUPINFO);
si.lpReserved = NULL;
si.lpDesktop = NULL;
si.lpTitle = programName;
si.cbReserved2 = 0;
si.lpReserved2 = NULL;

GetStartupInfo( &si );

if( ! wait_flag ) // IF WE DO NOT WAIT - RUN MINIMIZED
{
si.dwFlags = si.dwFlags | STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWMINIMIZED;
}

fSuccess = CreateProcess( programName,
commandLine,
(LPSECURITY_ATTRIBUTES) NULL, /* Process security */
(LPSECURITY_ATTRIBUTES) NULL, /* Thread Security */
(BOOL) TRUE, /* Inherit handles */
(DWORD) create_flags, /* Create Flags */
NULL, /* Environment: */
curDir, /* Current Dir */
(LPSTARTUPINFO) &si, /* Startup info */
(LPPROCESS_INFORMATION) π ); /* Process info */

if( fSuccess != 0 ) // SUCCESS IF != 0
{
dwExitCode = 0;
/* WAIT FOR TASK TO COMPLETE (NO_TIMEOUT): */
if(wait_flag)
{
dw = WaitForSingleObject(pi.hProcess, INFINITE );
// WAS PROCESS RUN SUCCESSFULLY:
fExit = GetExitCodeProcess(pi.hProcess, &dwExitCode );
return_status = dwExitCode;

CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
pi.hThread = 0;
pi.hProcess = 0;
} // END WAIT - SAVE THE EXIT CODE FROM PROGRAM
}
else /* CREATE PROCESS FAILED */
{
last_error = GetLastError();
return_status = -1;
}
if (hFileout) CloseHandle(hFileout);
return( return_status );
}

the function here is compiled and built into a dll. i dont know if it being in a dll is any cause for it to not work or not.

plz help.

thanx


  • Author

Well, since no one else has responded. I found the problem.

I was calling GetStartupInfo(&si) and overwriting the information I had set for redirecting the output. :}

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.