Author Topic: Execute system commands in a java script  (Read 8019 times)

Offline OriolLehmkuhl

  • PixInsight Addict
  • ***
  • Posts: 177
    • http://www.astrosurf.com/brego-sky
Execute system commands in a java script
« on: 2008 October 12 10:19:07 »
Hi folks,

we are trying to execute systems commands in a javascript without many success :? any idea?

Thanks,

Offline David Serrano

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 503
Re: Execute system commands in a java script
« Reply #1 on: 2008 October 12 14:05:43 »
Entiendo que en Edit > Security Settings has activado la opción "Allow execution of commands from JavaScript scripts", verdad? ;) ¿Qué intentos has hecho?

En este párrafo pondría el típico mensajito en letras grandes rojas, pero tengo la impresión de que no te hace falta ;).
--
 David Serrano

Offline OriolLehmkuhl

  • PixInsight Addict
  • ***
  • Posts: 177
    • http://www.astrosurf.com/brego-sky
Execute system commands in a java script
« Reply #2 on: 2008 October 12 14:24:06 »
Hola David :wink:,

lo que intentábamos era poder hacer unas cuantas operaciones de bash desde PI, un move y un wget. Pero no encontramos la manera de hacer un system (o lo equivalente a la clásica función de C), hemos visto que hay un execute en la consola, que si se hace lo que tu nos indicas se puede hacer servir para hacer algunas operaciones, pero no todas las que necesitamos.

Quizás mejor te explico lo que estamos haciendo y se ve una solución al tema. Bueno, lo que queremos hacer es un planificador de sesiones (un script). Algo que le digas un objeto de catalogo o unas coordenadas, un field of view y te baje del DSS la imagen (esto después se podría mejorar, poniendo inclinacion de cámara, efemérides, etc...). El problema es que el archivo que te da el DSS no tiene extensión (es un fit), y el open url del PI se raya, asi que tenemos que hacer un wget y despues un move antes de poderlo abrir con el pi  :?

Gracias :D

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Execute system commands in a java script
« Reply #3 on: 2008 October 12 15:34:49 »
Hola Oriol

To execute a system command from PixInsight's console, prepend an exclamation sign (!) to it.

For example, you can try:

Code: [Select]
!ls

to run the ls program (not PI's ls internal command, which is different).

On Windows, system commands must be executed via the "cmd" program. For example:

Code: [Select]
!cmd /c dir

would run the DIR command (the "equivalent" to ls on Windows).

You can use conditional directives to write code that runs on all supported platforms:

Code: [Select]
#ifeq __PI_PLATFORM__ MSWINDOWS
# define LS !cmd /c dir
#else
# define LS !ls -l
#endif


__PI_PLATFORM__ is a predefined macro that is always available to any script in PixInsight. Note that on Mac OS X you actually have a UNIX platform, so we have to care about Windows only. Hope this helps.

As David says, to execute commands from a script you need to enable the corresponding security settings. Don't expect your users to be too happy of having to do this, though. What are you doing that can't be done with the File object?

By the way, interesting project ;)
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline OriolLehmkuhl

  • PixInsight Addict
  • ***
  • Posts: 177
    • http://www.astrosurf.com/brego-sky
Execute system commands in a java script
« Reply #4 on: 2008 October 13 03:59:14 »
Hi Juan,

Thanks for your explanation, now we can execute the wget command without any trouble ;).  If all the other parts of the tool works as expected, this night we will be able to show a preview of the script :D

Regards