CSPyInterpreter and std output
Hi,
I've been reading the reference appendix on calling python scripts from within native applications. One thing I'd like to do is capture the script's output for processing within the native application -- how can I do that? Yes, I see the iStdO/I public prototypes and am guessing that they are part of the solution -- but how do I use them?
Thanks in advance!
Re: CSPyInterpreter and std output
[QUOTE][i]Originally posted by pollyp [/i]
[B]
One thing I'd like to do is capture the script's output for processing within the native application -- how can I do that? Yes, I see the iStdO/I public prototypes and am guessing that they are part of the solution -- but how do I use them?
[/B][/QUOTE]
Below some code snippets showing how to forward the output to a file:
[code]
// CMyTester.h:
/**
* File handle to script output
*/
RFile iResultFile;
/**
* Interpreter
*/
CSPyInterpreter* iInterpreter;
// CMyTester.cpp:
// Redirects output, called by the interpreter:
int CMyTester::CallSTDO(const char *buf, int n)
{
TPtrC8 from((TUint8*)buf);
HBufC* tgt = HBufC::NewLC(n);
TPtr data = tgt->Des();
data.Copy(from.Left(n));
TInt pos = 0;
pTester->iResultFile.Seek(ESeekEnd, pos);
pTester->iResultFile.Write(from.Left(n));
CleanupStack::PopAndDestroy(); //tgt
return n;
}
// pTester is a pointer to CMyTester instance, this is needed for CSPyInterpreter
// instance to access the private file handle in CMyTester instance
pTester->iInterpreter->iStdO = (CallSTDO); //Forward IO
[/code]