×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    20

    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!

  2. #2
    Regular Contributor
    Join Date
    Sep 2003
    Location
    Finland
    Posts
    209

    Re: CSPyInterpreter and std output

    Originally posted by pollyp

    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?
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •