Greetings,

Generally when I need to run a command line program from within a program
I am writing and the passing of arguments becomes to frustrating (as there
are many layers of retranslating the command syntax), I write a command
line command in the OS(es) native macro language, .bat/.cmd in your case.
Then the only thing that I need to get correct in the calling program is
executing the OS macro command itself - which you seem to have
accomplished.

Enjoy,

Fred


On Sun, February 8, 2026 3:22 am, Alan Hewat wrote:
> SharpCap <https://docs.sharpcap.co.uk/4.1/> is a popular astronomical
> imaging application and can be launched from a Windows cmd shell with
> a command-line
> argument <https://docs.sharpcap.co.uk/4.0/34_CommandLineArguments.htm>,
> like this:
> C:\Users\alanh>"..\\..\\Program Files\\SharpCap 4.1 (64
> bit)\\SharpCap.exe"
> /runscript d:\\cameraList.py
> This correctly launches SharpCap to run a Python script cameraList.py to
> list available cameras (or whatever else is requested).
>
> ImageJ has an exec() function
> <https://wsr.imagej.net/developer/macro/functions.html#E> that can be used
> to launch applications from an imageJ script. The following launches
> SharpCap, but apparently doesn't pass the /runscript argument correctly
> because SharpCap scripting reports an error and doesn't work.
> SharpCap = getDirectory("startup")+"..\\..\\Program Files\\SharpCap 4.1
> (64
> bit)\\SharpCap.exe";
> status=exec (SharpCap+" /runscript d:\\cameraList.py");
>
> Guided by the exec() function
> <https://imagej.net/ij/macros/ExecExamples.txt> examples, I tried instead:
> status=exec("cmd", "/c", "start", SharpCap, " /runscript", "
> d:\\cameraList.py" );
> but an error that "*Windows can't find /runscript*" is returned as if it
> thinks */runscript* is an application.
> Replacing */runscript* with the application *SharpCap* as below works, but
> I don't understand why
> status=exec("cmd", "/c", "start", SharpCap, SharpCap, " /runscript", "
> d:\\cameraList.py" );
> That launches SharpCap, and no error is reported, but the script is not
> executed.
>
> *The last attempt seems to be close to working, but I must have made some
> mistake in the exec() syntax.*
>
> The latest versions of imageJ and Win-11 were used. Any suggestions would
> be appreciated. Alan.
>
>
> --
> *_______________________________*
> Dr Alan Hewat, NeutronOptics
> Grenoble, FRANCE (from computer)
> [email protected]
> +33.476984168 VAT:FR79499450856
> http://NeutronOptics.com/hewat <http://neutronoptics.com/hewat>
> _______________________________
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

Reply via email to