Macro fails to open stack when launched from the commandline

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Macro fails to open stack when launched from the commandline

Stein Rørvik
Hello,

I have encountered a strange bug:
If a macro is launched from the commandline (Windows 7 64-bit, Java 1.6), any stack import silently fails UNLESS ImageJ is already running.

To reproduce the problem:

Demo macro to create a stack to be opened:

MacroMakeVirtualStack.ijm
----------------------------------------------------------------------
run("T1 Head (2.4M, 16-bits)");
dir = getDirectory("temp")+"T1-Head\\";
File.makeDirectory(dir);
run("Image Sequence... ", "format=TIFF save="+dir);
----------------------------------------------------------------------

Demo macro to open this stack:

MacroOpenVirtualStack.ijm
----------------------------------------------------------------------
dir = getDirectory("temp")+"T1-Head\\";
print("Dir to import: '" + dir + "'");
run("Image Sequence...", "open=&dir sort use");
print("Opened title: " + getTitle());
----------------------------------------------------------------------

Put the above in the ImageJ/macros folder and run this on the commandline (without ImageJ running)

ImageJ.exe -macro MacroOpenVirtualStack.ijm

The macro fails to open the stack.
Now go back to the command line and repeat the command, without closing ImageJ.
The macro now works as it should.

The problem occurs with both real and virtual stacks.
The problem occurs on three out of five computers I have tested it on; all running Windows 7 64-bit.
It occurs on both old and new versions of ImageJ (I tried 1.49 and 1.51r).
The computers it works on are the slowest ones, so I suspect it might be a timing issue.

Stein


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Macro fails to open stack when launched from the commandline

Michael Schmid
Hi Stein,

no such problem on a pretty fast Linux machine (ImageJ 1.51r27; Java
1.8.0_112 [64-bit])
I had to remove the trailing backslash in the 'dir' of
MacroOpenVirtualStack.ijm, however.

Maybe you have different Java versions on the different machines?
In case of a strange bug, in principle, there might be also differences
in the Edit>Options>IO Options that could cause different behavior (e.g.
the settings of "Use file chooser to import sequences"), but I consider
this unlikely.


Michael
________________________________________________________________
On 30/10/2017 15:13, Stein Rørvik wrote:

> Hello,
>
> I have encountered a strange bug:
> If a macro is launched from the commandline (Windows 7 64-bit, Java 1.6), any stack import silently fails UNLESS ImageJ is already running.
>
> To reproduce the problem:
>
> Demo macro to create a stack to be opened:
>
> MacroMakeVirtualStack.ijm
> ----------------------------------------------------------------------
> run("T1 Head (2.4M, 16-bits)");
> dir = getDirectory("temp")+"T1-Head\\";
> File.makeDirectory(dir);
> run("Image Sequence... ", "format=TIFF save="+dir);
> ----------------------------------------------------------------------
>
> Demo macro to open this stack:
>
> MacroOpenVirtualStack.ijm
> ----------------------------------------------------------------------
> dir = getDirectory("temp")+"T1-Head\\";
> print("Dir to import: '" + dir + "'");
> run("Image Sequence...", "open=&dir sort use");
> print("Opened title: " + getTitle());
> ----------------------------------------------------------------------
>
> Put the above in the ImageJ/macros folder and run this on the commandline (without ImageJ running)
>
> ImageJ.exe -macro MacroOpenVirtualStack.ijm
>
> The macro fails to open the stack.
> Now go back to the command line and repeat the command, without closing ImageJ.
> The macro now works as it should.
>
> The problem occurs with both real and virtual stacks.
> The problem occurs on three out of five computers I have tested it on; all running Windows 7 64-bit.
> It occurs on both old and new versions of ImageJ (I tried 1.49 and 1.51r).
> The computers it works on are the slowest ones, so I suspect it might be a timing issue.
>
> Stein

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Macro fails to open stack when launched from the commandline

Stein Rørvik
I am running vanilla ImageJ with the Java 1.6 runtime as a subfolder in the ImageJ folder so the java version is therefore 100% identical across all tested systems. I also tested it with Java 1.8 and had the same problem.
The File chooser option should be irrelevant as this is a macro problem, it does not happen if I import via the GUI.

Stein

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid
Sent: 31. oktober 2017 09:36
To: [hidden email]
Subject: Re: Macro fails to open stack when launched from the commandline

Hi Stein,

no such problem on a pretty fast Linux machine (ImageJ 1.51r27; Java
1.8.0_112 [64-bit])
I had to remove the trailing backslash in the 'dir' of MacroOpenVirtualStack.ijm, however.

Maybe you have different Java versions on the different machines?
In case of a strange bug, in principle, there might be also differences in the Edit>Options>IO Options that could cause different behavior (e.g.
the settings of "Use file chooser to import sequences"), but I consider this unlikely.


Michael
________________________________________________________________
On 30/10/2017 15:13, Stein Rørvik wrote:

> Hello,
>
> I have encountered a strange bug:
> If a macro is launched from the commandline (Windows 7 64-bit, Java 1.6), any stack import silently fails UNLESS ImageJ is already running.
>
> To reproduce the problem:
>
> Demo macro to create a stack to be opened:
>
> MacroMakeVirtualStack.ijm
> ----------------------------------------------------------------------
> run("T1 Head (2.4M, 16-bits)");
> dir = getDirectory("temp")+"T1-Head\\"; File.makeDirectory(dir);
> run("Image Sequence... ", "format=TIFF save="+dir);
> ----------------------------------------------------------------------
>
> Demo macro to open this stack:
>
> MacroOpenVirtualStack.ijm
> ----------------------------------------------------------------------
> dir = getDirectory("temp")+"T1-Head\\"; print("Dir to import: '" + dir
> + "'"); run("Image Sequence...", "open=&dir sort use"); print("Opened
> title: " + getTitle());
> ----------------------------------------------------------------------
>
> Put the above in the ImageJ/macros folder and run this on the
> commandline (without ImageJ running)
>
> ImageJ.exe -macro MacroOpenVirtualStack.ijm
>
> The macro fails to open the stack.
> Now go back to the command line and repeat the command, without closing ImageJ.
> The macro now works as it should.
>
> The problem occurs with both real and virtual stacks.
> The problem occurs on three out of five computers I have tested it on; all running Windows 7 64-bit.
> It occurs on both old and new versions of ImageJ (I tried 1.49 and 1.51r).
> The computers it works on are the slowest ones, so I suspect it might be a timing issue.
>
> Stein

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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Macro fails to open stack when launched from the commandline

Stein Rørvik
In reply to this post by Stein Rørvik
I wrote in my previous post that this issue was already present in version 1.49v;
today I tried to downgrade to version 1.48v and then it worked.
It does not matter what Java version I run it on.

Stein

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Stein Rørvik
Sent: 30. oktober 2017 15:13
To: [hidden email]
Subject: Macro fails to open stack when launched from the commandline

[This sender failed our fraud detection checks and may not be who they appear to be. Learn about spoofing at http://aka.ms/LearnAboutSpoofing]

Hello,

I have encountered a strange bug:
If a macro is launched from the commandline (Windows 7 64-bit, Java 1.6), any stack import silently fails UNLESS ImageJ is already running.

To reproduce the problem:

Demo macro to create a stack to be opened:

MacroMakeVirtualStack.ijm
----------------------------------------------------------------------
run("T1 Head (2.4M, 16-bits)");
dir = getDirectory("temp")+"T1-Head\\";
File.makeDirectory(dir);
run("Image Sequence... ", "format=TIFF save="+dir);
----------------------------------------------------------------------

Demo macro to open this stack:

MacroOpenVirtualStack.ijm
----------------------------------------------------------------------
dir = getDirectory("temp")+"T1-Head\\";
print("Dir to import: '" + dir + "'");
run("Image Sequence...", "open=&dir sort use"); print("Opened title: " + getTitle());
----------------------------------------------------------------------

Put the above in the ImageJ/macros folder and run this on the commandline (without ImageJ running)

ImageJ.exe -macro MacroOpenVirtualStack.ijm

The macro fails to open the stack.
Now go back to the command line and repeat the command, without closing ImageJ.
The macro now works as it should.

The problem occurs with both real and virtual stacks.
The problem occurs on three out of five computers I have tested it on; all running Windows 7 64-bit.
It occurs on both old and new versions of ImageJ (I tried 1.49 and 1.51r).
The computers it works on are the slowest ones, so I suspect it might be a timing issue.

Stein


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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Macro fails to open stack when launched from the commandline

Stein Rørvik
I also wrote in my previous posting that this issue does not occur on all ImageJ installations I have.
Now I found out what makes this bug happen or not:
It only fails if ImageJ has a Startup macro installed.

My macros/RunAtStartup.ijm launches a custom toolset:
--------------------------------------------------
run("Install...", "install=["+getDirectory("macros") + "toolsets\\SR Custom Tools.ijm"+"]");
--------------------------------------------------
If I remove RunAtStartup.ijm, my stack import macro from the command line works as it should.

It also works if I insert a small delay at the end of the startup macro:
--------------------------------------------------
run("Install...", "install=["+getDirectory("macros") + "toolsets\\SR Custom Tools.ijm"+"]");
wait(1000);
--------------------------------------------------
So the problem is indeed a timing issue; probably the command line macro tries to run too soon before the startup macros has properly finished.

Stein

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Stein Rørvik
Sent: 30. oktober 2017 15:13
To: [hidden email]
Subject: Macro fails to open stack when launched from the commandline

[This sender failed our fraud detection checks and may not be who they appear to be. Learn about spoofing at http://aka.ms/LearnAboutSpoofing]

Hello,

I have encountered a strange bug:
If a macro is launched from the commandline (Windows 7 64-bit, Java 1.6), any stack import silently fails UNLESS ImageJ is already running.

To reproduce the problem:

Demo macro to create a stack to be opened:

MacroMakeVirtualStack.ijm
----------------------------------------------------------------------
run("T1 Head (2.4M, 16-bits)");
dir = getDirectory("temp")+"T1-Head\\";
File.makeDirectory(dir);
run("Image Sequence... ", "format=TIFF save="+dir);
----------------------------------------------------------------------

Demo macro to open this stack:

MacroOpenVirtualStack.ijm
----------------------------------------------------------------------
dir = getDirectory("temp")+"T1-Head\\";
print("Dir to import: '" + dir + "'");
run("Image Sequence...", "open=&dir sort use"); print("Opened title: " + getTitle());
----------------------------------------------------------------------

Put the above in the ImageJ/macros folder and run this on the commandline (without ImageJ running)

ImageJ.exe -macro MacroOpenVirtualStack.ijm

The macro fails to open the stack.
Now go back to the command line and repeat the command, without closing ImageJ.
The macro now works as it should.

The problem occurs with both real and virtual stacks.
The problem occurs on three out of five computers I have tested it on; all running Windows 7 64-bit.
It occurs on both old and new versions of ImageJ (I tried 1.49 and 1.51r).
The computers it works on are the slowest ones, so I suspect it might be a timing issue.

Stein


--
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
Reply | Threaded
Open this post in threaded view
|

Re: Macro fails to open stack when launched from the commandline

Stein Rørvik
I did some further testing and found out that the problem is simply related to the length of the macro file ImageJ launches at startup. The file in question has a section of code (12kb) which is disabled by /*....*/ comments. If I remove this disabled section, the macro launched from the command line works fine. So it is definitely a timing issue; since removal of out-commented code should not matter functionally; it just delays some milliseconds in the parser.

Stein

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Stein Rørvik
Sent: 06. november 2017 12:58
To: [hidden email]
Subject: Re: Macro fails to open stack when launched from the commandline

[This sender failed our fraud detection checks and may not be who they appear to be. Learn about spoofing at http://aka.ms/LearnAboutSpoofing]

I also wrote in my previous posting that this issue does not occur on all ImageJ installations I have.
Now I found out what makes this bug happen or not:
It only fails if ImageJ has a Startup macro installed.

My macros/RunAtStartup.ijm launches a custom toolset:
--------------------------------------------------
run("Install...", "install=["+getDirectory("macros") + "toolsets\\SR Custom Tools.ijm"+"]");
--------------------------------------------------
If I remove RunAtStartup.ijm, my stack import macro from the command line works as it should.

It also works if I insert a small delay at the end of the startup macro:
--------------------------------------------------
run("Install...", "install=["+getDirectory("macros") + "toolsets\\SR Custom Tools.ijm"+"]"); wait(1000);
--------------------------------------------------
So the problem is indeed a timing issue; probably the command line macro tries to run too soon before the startup macros has properly finished.

Stein

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Stein Rørvik
Sent: 30. oktober 2017 15:13
To: [hidden email]
Subject: Macro fails to open stack when launched from the commandline

[This sender failed our fraud detection checks and may not be who they appear to be. Learn about spoofing at http://aka.ms/LearnAboutSpoofing]

Hello,

I have encountered a strange bug:
If a macro is launched from the commandline (Windows 7 64-bit, Java 1.6), any stack import silently fails UNLESS ImageJ is already running.

To reproduce the problem:

Demo macro to create a stack to be opened:

MacroMakeVirtualStack.ijm
----------------------------------------------------------------------
run("T1 Head (2.4M, 16-bits)");
dir = getDirectory("temp")+"T1-Head\\";
File.makeDirectory(dir);
run("Image Sequence... ", "format=TIFF save="+dir);
----------------------------------------------------------------------

Demo macro to open this stack:

MacroOpenVirtualStack.ijm
----------------------------------------------------------------------
dir = getDirectory("temp")+"T1-Head\\";
print("Dir to import: '" + dir + "'");
run("Image Sequence...", "open=&dir sort use"); print("Opened title: " + getTitle());
----------------------------------------------------------------------

Put the above in the ImageJ/macros folder and run this on the commandline (without ImageJ running)

ImageJ.exe -macro MacroOpenVirtualStack.ijm

The macro fails to open the stack.
Now go back to the command line and repeat the command, without closing ImageJ.
The macro now works as it should.

The problem occurs with both real and virtual stacks.
The problem occurs on three out of five computers I have tested it on; all running Windows 7 64-bit.
It occurs on both old and new versions of ImageJ (I tried 1.49 and 1.51r).
The computers it works on are the slowest ones, so I suspect it might be a timing issue.

Stein


--
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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Macro fails to open stack when launched from the commandline

Wayne Rasband-2
In reply to this post by Stein Rørvik
> On Nov 6, 2017, at 6:18 AM, Stein Rørvik <[hidden email]> wrote:
>
> Hello,
>
> I have encountered a strange bug:
> If a macro is launched from the commandline (Windows 7 64-bit, Java 1.6), any stack import silently fails UNLESS ImageJ is already running.

This  problem is fixed in the latest ImageJ daily build (1.51s23). It fixes bugs that caused the RunAtStartup, AutoRun and command line macros to interfere with each other, causing &variable expansion in run() macro calls to not work. To avoid this interference, the RunAtStartup macro (created by the Edit>Options>Startup command), the AutoRun macro (in StartupMacros) and command line macros now all run on the same thread.

-wayne


> To reproduce the problem:
>
> Demo macro to create a stack to be opened:
>
> MacroMakeVirtualStack.ijm
> ----------------------------------------------------------------------
> run("T1 Head (2.4M, 16-bits)");
> dir = getDirectory("temp")+"T1-Head\\";
> File.makeDirectory(dir);
> run("Image Sequence... ", "format=TIFF save="+dir);
> ----------------------------------------------------------------------
>
> Demo macro to open this stack:
>
> MacroOpenVirtualStack.ijm
> ----------------------------------------------------------------------
> dir = getDirectory("temp")+"T1-Head\\";
> print("Dir to import: '" + dir + "'");
> run("Image Sequence...", "open=&dir sort use"); print("Opened title: " + getTitle());
> ----------------------------------------------------------------------
>
> Put the above in the ImageJ/macros folder and run this on the commandline (without ImageJ running)
>
> ImageJ.exe -macro MacroOpenVirtualStack.ijm
>
> The macro fails to open the stack.
> Now go back to the command line and repeat the command, without closing ImageJ.
> The macro now works as it should.
>
> The problem occurs with both real and virtual stacks.
> The problem occurs on three out of five computers I have tested it on; all running Windows 7 64-bit.
> It occurs on both old and new versions of ImageJ (I tried 1.49 and 1.51r).
> The computers it works on are the slowest ones, so I suspect it might be a timing issue.
>
> Stein

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