Login  Register

Re: Execute Windows cmd commands within macro language

Posted by Stein Rørvik on Oct 30, 2017; 2:44pm
URL: http://imagej.273.s1.nabble.com/Execute-Windows-cmd-commands-within-macro-language-tp5019610p5019639.html

You are trying to use the Windows start command.
That needs its parameters to be enclosed with hyphens.

The syntax is

start "Window Title" "C:\path to folder\path to file"

You need to escape the commands properly to get the hyphens and backslashes correctly.

In ImageJ this would be something like
exec("cmd", "/c", "start", "\"Window Title\"", "\"C:\\path to folder\\path to file\"");
You need to do a few trials and errors to get this right.
Forward slashes instead of backslashes usually work and do not need escaping.

And - are you sure you need to use the windows start command?
That is normally used when you want to start something and NOT wait for it to complete.
That is probably not what you want in an image processing workflow.

Try instead
exec("cmd", "/c", "\"C:\\path to folder\\path to file\"");
if the file you want to open is already openable on the Windows commandline,

or just
exec("\"C:\\path to folder\\path to file\"");
if your file is an executable that can run by itself.

With parameters, e.g. to run a script:
exec("\"C:\\path to scripting language\\program.exe\"", "\"C:\\path to some folder\\file containing script\"");

Hope this helps.

Stein

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Gregory James
Sent: 27. oktober 2017 10:57
To: [hidden email]
Subject: Re: Execute Windows cmd commands within macro language

Thank you to all the people that replied to me publicly and privately.

I have sorted my problem so will post the solution to the ImageJ community...

The command required is indeed...

exec("cmd", "/c", "start", path);

... where 'path' is the path to the .bat file that you want to execute.

In the Windows cmd command prompt, the path is allowed to have spaces in it, but it seems (at least for my version of ImageJ) that the path is *NOT* allowed to have any spaces in it in the macro language. I find this slightly strange as I've not had this problem before. My experience is that ImageJ tends to be happy with spaces in string file paths. Perhaps someone more knowledgeable than myself could enlighten the community and explain what is happening here?

Thanks,

Greg (Birmingham, UK)

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

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