
edrabbit1.552491848548566E12 asked a question.
Capturing stdOutput and stdError from LaunchApplication
I'm attempting to capture the output from an executable launched from LaunchApplication, but all I'm getting is a blank file created. I've put together a sample project to try to get anything outputting to a text file, but no luck. All I get is the file created but with no contents. Here's my current Setup.rul:
include "ifx.h"
export prototype MyFunction(HWND);
prototype Kernel32.CloseHandle(HWND);
prototype HWND Kernel32.CreateFileA(STRING, NUMBER, NUMBER, NUMBER, NUMBER, NUMBER, NUMBER);
///////////////////////////////////////////////////////////////////////////////
// Function: MyFunction
///////////////////////////////////////////////////////////////////////////////
function MyFunction(hMSI)
HWND stdOutput;
STRING szDir, szProgram, szCmdLine;
begin
LAAW_PARAMETERS.bInheritHandles = TRUE;
stdOutput = Kernel32.CreateFileA("C:\\temp\\log.log", GENERIC_WRITE, 2, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
LAAW_STARTUPINFO.dwFlags = LAAW_STARTUPINFO.dwFlags | STARTF_USESTDHANDLES;
LAAW_STARTUPINFO.hStdOutput = stdOutput;
LAAW_STARTUPINFO.hStdError = stdOutput;
szProgram = "c:\\windows\\system32\\getmac.exe";
szCmdLine = "";
LaunchApplication(szProgram, szCmdLine, "c:\\temp", SW_SHOWNORMAL, 1000, LAAW_OPTION_WAIT);
Kernel32.CloseHandle(stdOutput);
MessageBox("Check file", INFORMATION);
end;
Anyone have any luck capturing the stdout and stderr from InstallScript? I'm able to get the return code just fine, but I need more info than that.
Thanks
I'm mainly looking to use this for troubleshooting installs. I can grab the error code that we return, but the output (both stdoutput and stderror) gives some extra info that would be handy.
I've not yet been able to work out how to get this going without an intermediate file. But, the "Easy Way" methods you can probably use:
1. Passing an output redirect on the commandline:
getmac.exe > c:\myfile.txt
Then reading in from the file after it's done. This looks like it's what you're already trying by redirecting STDOUT via setting handles and such.
2. Using C, which is much simpler. Here's an except from something I have working, reading from a child process's STDOUT and writing to the parent process's console window:
string tmpFolder, stdOut;
tmpFolder = System.Environment.GetEnvironmentVariable("TEMP");
string AppPath = Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName;
AppPath = System.IO.Path.GetDirectoryName(AppPath);
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = AppPath + "\\sftinfo.exe";
p.StartInfo.Arguments = "\"" + manifest + "\" -M \"" + tmpFolder + "\\sftinfo.xml.nfo\"";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
stdOut = p.StandardOutput.ReadToEnd();
Console.Write(stdOut);
-RussHere's how I got it to work: