Author Topic: starting external process from script  (Read 5838 times)

Offline kwiechen

  • PixInsight Addict
  • ***
  • Posts: 186
starting external process from script
« on: 2011 November 13 04:55:08 »
Hello,

is it possible to start an external process from a script - for example to make a new directory?

Best

Kai


Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: starting external process from script
« Reply #1 on: 2011 November 13 06:04:51 »
I think this was added a while back when Georg integrated astrometry.net executables. Search for astrometry.net and see if it provides hints.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline kwiechen

  • PixInsight Addict
  • ***
  • Posts: 186
Re: starting external process from script
« Reply #2 on: 2011 November 13 06:25:59 »
I have found this: http://pixinsight.com/forum/index.php?topic=2903.0

Is there a new option to start an external process? The Core JavaScript Objects list contains an ExternalProcess module but I have not found an example or documentation. The API appears similar to the Qt4 QProcess class.

Best

Kai




Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: starting external process from script
« Reply #3 on: 2011 November 14 01:02:12 »
Hi Kai,

Unfortunately the ExternalProcess object is mostly broken in 1.7; I'll fix it in the next version (not before Qt 4.8 is released, though).

For now you can run an external process with code like this:

#include <pjsr/ProcessExitStatus.jsh>

var exitCode = ExternalProcess.execute( "ls", [ "-la", "/tmp" ] );
if ( exitCode != ProcessExitStatus_Normal )
   throw new Error( "The process crashed. Exit code: " + exitCode.toString() );


but due to the existing bugs you can't read output data generated by the process (data written to stdout or stderr by the executed process). You can also start a program as a detached process (a daemon in Linux/UNIX):

var exitCode = ExternalProcess.startDetached( "aprogram with its arguments" );

I apologize for the inconvenience. ExternalProcess will work correctly in the next version.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline kwiechen

  • PixInsight Addict
  • ***
  • Posts: 186
Re: starting external process from script
« Reply #4 on: 2011 November 14 11:46:35 »
Hello Juan,

thank you for your help!

Best,

Kai


Offline kwiechen

  • PixInsight Addict
  • ***
  • Posts: 186
Re: starting external process from script
« Reply #5 on: 2012 December 23 03:31:50 »
Hi Juan,

is PJSR/ExternalProcess still broken in part? I have tried to write handlers for ExternalProcess.onStarted and ExternalProcess.onFinished and
got

Error: ExternalProcess.Set(): Internal error.

Kai


test code was:


function main()
{
   Console.show();

   var ext = new ExternalProcess();
   ext.onStarted = function()
   {
      Console.writeln("started");
   };
   ext.onFinished = function()
   {
      Console.writeln("finished");
   };
   
   var program = "c:/users/kai_2/desktop/curl";
   var args = new Array;
   args.push("--help");
   ext.start(program, args);
}

main();


Offline kwiechen

  • PixInsight Addict
  • ***
  • Posts: 186
Re: starting external process from script
« Reply #6 on: 2012 December 24 02:48:37 »
1.8 RC1 works as expected!

Thank you!

Kai