Author Topic: Script Console command  (Read 3116 times)

Offline CraigNZ

  • PixInsight Enthusiast
  • **
  • Posts: 94
Script Console command
« on: 2016 May 04 22:21:16 »
A script can send text to the console for display, but can a script send a command to the console.  For example, can a script send a log command (log -f...) to open a log file.

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Script Console command
« Reply #1 on: 2016 May 11 01:24:54 »
Quote
can a script send a command to the console

This is not possible, both for security reasons and because the scripting engine is not reentrant. In the next version a module will be able to execute JavaScript code, under some security constraints.

Quote
For example, can a script send a log command (log -f...) to open a log file.

You don't need the log command to do this from a script. Use the Console.beginLog() and Console.endLog() static methods. For example:

Console.beginLog();
// ... do your stuff here
let consoleText = Console.endLog().toString();


Let me know if this helps.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline CraigNZ

  • PixInsight Enthusiast
  • **
  • Posts: 94
Re: Script Console command
« Reply #2 on: 2016 May 11 12:31:32 »
Hi Juan,

I looked at the Console class but didn't see these .. I think this will do it.  Is there any documentation on them?

I think the call BeginLog is used to place all console messages to an array and endlog is used to stop it, and the contents of the byte array can then be written to a file.

If so, then if for example, AperturePhotometry, which calls other scripts is used, will the beginlog carry over into those scripts also, or is it capturing only the script it is called from?

Offline CraigNZ

  • PixInsight Enthusiast
  • **
  • Posts: 94
Re: Script Console command
« Reply #3 on: 2016 May 11 12:55:53 »

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Script Console command
« Reply #4 on: 2016 May 11 13:45:26 »
Quote
Is there any documentation on them?

Unfortunately not. Writing PJSR documentation is a long-standing pending task. Hopefully I'll find the necessary time---and motivation---to write it after completing other priority tasks I am currently involved in. I am always here to help, of course.

Quote
I think the call BeginLog is used to place all console messages to an array and endlog is used to stop it

Well, it is actually more complex than that, but that's a valid top-level description.

Quote
and the contents of the byte array can then be written to a file.

Sure. For example:

Console.beginLog();
// ... do your stuff here
let consoleText = Console.endLog(); // consoleText = console text in UTF8 format
let file = File.createFileForWriting( "/path/to/file.txt" );
file.write( consoleText );
file.close();


will the beginlog carry over into those scripts also, or is it capturing only the script it is called from?

Console text output will be recorded from the call to Console.beginLog() until Console.endLog(). As far as none of those scripts call Console.endLog(), console logging will work irrespective of what scripts are being executed.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline CraigNZ

  • PixInsight Enthusiast
  • **
  • Posts: 94
Re: Script Console command
« Reply #5 on: 2016 May 11 14:02:36 »
Thanks Juan, looks like this will do it .. I'll try it later today.

Craig

Offline CraigNZ

  • PixInsight Enthusiast
  • **
  • Posts: 94
Re: Script Console command
« Reply #6 on: 2016 May 11 22:00:07 »
Works perfectly. All of the console text is captured including those from called scripts.  What I can now do is make this an option on the output tab and enter a file name.  Checking the 'log file' box will then execute the log statements.  I will also add an option to generate a single log file or a log file for each image being processed.  This makes it easy then for traceability when examining the data further on or going back in the archives to see what I did.

Thanks heaps.