Hi Alan,
in contrast to shell scripts under Linux, which are executable like
programs, you can run Windows batch files only via cmd /c, as you got it
already.
If you don't manage to pass an argument to the batch file (I cannot try
since I am working under linux), you could have a fixed place and name
for the file where you pass the parameters.
An obvious place might be the %TEMP% directory, but I am not sure
whether it is still the same as getDir("temp") in ImageJ macros; you
have to try.
(In the old times, both was C:\Windows\Temp, but it has changed to
C:\Users\User Name\AppData\Local\Temp for Windows; not sure whether java
knows this)
Michael
________________________________________________________________
On 09.02.26 16:50, Alan Hewat wrote:
Thanks Fred.
Unfortunately *ImageJ exec() doesn't run Windows .bat files as expected
either :-(*
I have a simple .bat file containing one line, that *executes without error
when I double-click it in Windows*
"C:\Program Files\SharpCap 4.1 (64 bit)\SharpCap.exe" /language=fr
It launches SharpCap <https://docs.sharpcap.co.uk/4.1/>, a popular imaging
application for astronomers, with a command-line argument that specifies
the language
If instead I execute it within an imageJ script with
status = exec("C:\Program Files\SharpCap 4.1 (64 bit)\SharpCap.exe"
/language=fr);
It launches SharpCap but the in-line argument disables SharpCap's own
IronPython script with a "codepage___0" error.
(It does work without the in-line argument, and I want to input more
complicated arguments than the trivial /language).
Other users have reported similar problems and it was suggested
<https://forums.sharpcap.co.uk/viewtopic.php?t=6762>that the code page or
environment variables may be set differently.
This problem occurs however I try to execute SharpCap with exec(), e.g.
https://wsr.imagej.net/macros/ExecExamples.txt
There is a nice example
<https://imagej.net/ij/macros/tools/VideoCaptureTool.txt> of using exec()
with command-line arguments to record and playback VirtualDub video
That works for me, but doesn't help me understand my problem.
*So is there any other way of launching a Windows process from an imageJ
macro other than exec() ?*
Regards, Alan.
On Mon, 9 Feb 2026 at 05:45, Fred Damen <[email protected]> wrote:
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
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html