Capturing Output from Command Processor

Hello,

I would like to inquire about the possibilities of capturing text output from the Command Processor. I know that the ListMessages ON command displays a log with all commands, but I'm wondering if there's a way to directly access this output - for example, by storing it in a variable or external file?

Thank you in advance for your responses and have a nice day.

Best regards,

Richard

  • You're looking for the Logging command;

    LOGGING [SeverityLevel], [Filename], [ERASE]

    Where SeverityLevel will set what is logged (7 being pretty much everything and 1 just messages - you can look it up in the Commands help file within ChemStation).  You'll also want to check out the SetVerbose command, which increases the details;

    SetVerbose VerboseLevel

    I usually log at 7 with verbose set at 3 if I'm trying to get the most information.  Just remember to set the verbose back to 0 after you're done logging, since it slows things down considerably by showing up in the command line.

  • Thank you for your response regarding the Logging command. This is exactly what I was looking for.

    However, I have one more question. The file stores a lot of data and the last line is most important for me. How can I use a macro to read only the last line?

    When I tried this code:
    Open "log_path" for input as #7
    Input
    #7, line$
    Close
    #7
    print
    line$

    it only read the first line of the file.

  • Yes, it will read lines progressively each time you run the command.  Unfortunately, it doesn't look like there is a EOF function in ChemStation OpenLab CDS like there is for MSD Chemstation.  There was also something along a 'lastline' that would return the last line printed but I can't recall which software it was from or find it now.  One option would be to go through every line on the file until it errors out when it reaches the end of the file; you'd probably want to limit the amount that is outputted to the original file in this case, so take a look at the different severity levels for the Logging command, as well as the different verbose levels for the SetVerbose command.  Then it should go something like this;

    name readLastLine
    parameter filePathName$ default ""

    local errorNumber, lastLine$
    OPEN filePathName$ FOR INPUT as #33
    errorNumber = 0
    ON ERROR errorNumber = 1
    While (errorNumber = 0)
      INPUT #33, lastLine$
    EndWhile

    endMacro

    Then you can either print/alert the lastLine$ to the command line/user or log it to a text file.  Curious about what exactly you are trying to achieve since there may be a better way to go about it.

  • Thank you for your previous solution. I would like to follow up with the following issue:

    Your solution for reading command line output works perfectly. However, I've encountered a complication when working with files during active logging. When logging is enabled, I get an error message "Could not open file: log_path" when trying to open the file using the OPEN command. With files where logging is not active, everything works without issues.

    Do you have any recommendations on how to solve this problem? I thought about this solution - turn on logging, execute the command, turn off logging, and then read the last line with the response. Is this the correct approach? Or is there another, more elegant solution?

    Thank you for your help.

  • Unfortunately, you will not be able to access the file while it is opened by ChemStation.  I'm not exactly sure what it is you are trying to accomplish by trying to read the last logged line, but if you explain the goal, there might be a more elegant way to go about it.

  • As part of my project, I'm sending commands externally (from Python) to the Command Processor, and I would like to capture the output into an external file so I can read it later. For example, when I use Print to display a variable or when there's an error, I want to be able to read this output externally.

    Logging seemed like a promising way to get the desired response. The last line from logging would be saved to a file that I could then read from my Python script.

    Is there a better way to access CP output (either printed variables or error messages)?

    Thank you for any suggestions.

Was this helpful?