You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _pages/learn/headless.md
+17-23Lines changed: 17 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,38 +10,33 @@ However, it acquired [macro](/scripting/macro) capabilities, a [batch mode](/scr
10
10
11
11
Naturally, users want to execute such [macros](/scripting/macro) or [scripts](/scripting) in environments such as clusters where there is no graphical user interface available.
12
12
13
-
# `--headless` mode
13
+
##`--headless` mode
14
14
15
15
To address all of these needs, [ImageJ2](/software/imagej2) provides the capability to execute ImageJ plugins, macros and scripts in headless mode. This feature uses bytecode manipulation to patch ImageJ's behavior at runtime, making it possible to start ImageJ in batch mode without instantiating GUI components.
16
16
17
17
**Shortcoming:** There are plugins which are even more bound to a GUI than
18
18
ImageJ is. Naturally, these plugins will still try to instantiate GUI
19
19
elements when being called in headless mode, failing.
20
20
21
-
## Running scripts in headless mode
21
+
###Running scripts in headless mode
22
22
23
23
Please see the [headless scripting guide](/scripting/headless).
24
24
25
-
## Running macros in headless mode
25
+
###Running macros in headless mode
26
26
27
-
To run a *macro* in headless mode via a command prompt, first open a command prompt in the Fiji.app or ImageJ directory where the .exe (on windows) of ImageJ resides. Then use the following syntax, with the `-macro` command line argument along with the `--headless` option, as follows:
27
+
To run a *macro* in headless mode via a command prompt, first open a command prompt in the directory where a Fiji installation resides. Then use the following syntax, with the `-macro` command line argument along with the `--headless` option, as follows:
The `--console` flag is optional, it only ensures that print statements and error messages are shown in the command prompt.
33
-
However, **it also has a side effect of preventing the command prompt from "returning" after execution**, in effect giving the impression that the code is hanging. This is especially not desirable if calling ImageJ from an external program : the external program would just wait indefinitly for the execution to terminate.
34
-
**An external program can still access the printed statements without the `--console` flag**, by redirecting the standard/error output of the process (ImageJ.exe).
35
-
36
-
If you omit the `--headless` flag, the GUI will open and the macro will be executed.
32
+
If you omit the `--headless` flag, the GUI will open and the macro will be executed.
37
33
38
34
If the macro resides in ImageJ's macro directory, it is possible to specify the macro name instead of the actual file path. The file extension is always very recommended but for backwards compatibility, it is not strictly required *only* when specifying the macro name instead of a path.
In that case, the RunBatch.ijm file should be something like:
@@ -59,11 +54,10 @@ the `getArgument()` is used to grab the parameter string itself, and it is then
59
54
60
55
{% include notice icon="warning" content='Please note that you will not be able to use [script parameters](/scripting/parameters) with `-macro`. Follow instructions in [Scripting Headless](/scripting/headless) instead.' %}
61
56
62
-
Some ImageJ commands relying on the GUI do not work in headless mode such as :
63
-
-`selectWindow("name")`, use `selectImage(title)` instead for images
57
+
Some commands relying on the GUI do not work in headless mode such as:
58
+
-`selectWindow("name")`, use `selectImage(title)` instead for images
64
59
-`Table.Rename("oldTitle", "newTitle")`
65
60
66
-
67
61
{% capture historical-note %}
68
62
Headless support was originally a branch in [ImageJA](/libs/imageja); it worked
69
63
by putting rewritten versions of three core ImageJ classes into a file called
@@ -79,8 +73,7 @@ launching ImageJ from the command line.
79
73
{% endcapture %}
80
74
{% include aside title="Historical note" content=historical-note %}
81
75
82
-
83
-
# Why is `--headless` needed?
76
+
## Why is `--headless` needed?
84
77
85
78
Java *does* support a headless mode via the `java.awt.headless` property; setting this property to `true` enables it.
86
79
@@ -90,16 +83,17 @@ Since ImageJ was devised as a desktop application, everything -- including macro
90
83
91
84
On macOS, there is no problem: Aqua provides GUI-independent text rendering (mapping to the actual display using anti-aliasing). There, running in headless mode allows instantiating GUI elements such as the menu bar.
92
85
93
-
# Other solutions
94
-
## Xvfb virtual desktop
86
+
## Other solutions
87
+
88
+
### Xvfb virtual desktop
95
89
96
90
Another method is to have a virtual desktop, e.g. {% include wikipedia title='Xvfb' text='Xvfb'%}. This will allow ImageJ to start with a virtualised graphical desktop.
97
91
98
92
**Advantage:** No run-time patching is required.
99
93
100
94
**Shortcomings:** It is slower than it needs to be because of the overhead of starting the GUI, it is harder to configure, and plugins might get stuck because they wait for user input which never comes.
101
95
102
-
### Examples
96
+
####Examples
103
97
104
98
Here are a couple of simple examples.
105
99
@@ -109,7 +103,7 @@ Passing direct arguments:
109
103
$ cat hello.js
110
104
importClass(Packages.ij.IJ);
111
105
IJ.log("hello " + arguments[0]);
112
-
$ xvfb-run -a $IMAGEJ_DIR/ImageJ-linux64 hello.js Emerson
106
+
$ xvfb-run -a $FIJI_DIR/fiji hello.js Emerson
113
107
hello Emerson
114
108
```
115
109
@@ -120,7 +114,7 @@ $ cat hello-with-params.js
120
114
// @String name
121
115
importClass(Packages.ij.IJ);
122
116
IJ.log("hello " + name);
123
-
$ xvfb-run -a $IMAGEJ_DIR/ImageJ-linux64 --ij2 --headless --run hello-with-params.js 'name="Emerson"'
117
+
$ xvfb-run -a $FIJI_DIR/fiji --ij2 --headless --run hello-with-params.js 'name="Emerson"'
124
118
hello Emerson
125
119
```
126
120
@@ -143,6 +137,6 @@ wait # waits until all 'program' processes are finished
143
137
144
138
See also [this post on the ImageJ mailing list](https://list.nih.gov/cgi-bin/wa.exe?A2=IMAGEJ;5ace1ed0.1508).
145
139
146
-
## Rewriting as scripts or plugins
140
+
###Rewriting as scripts or plugins
147
141
148
142
The most robust method is to rewrite macros as scripts that do not require interaction with the GUI to begin with. Unfortunately, this is the most involved solution, too, since it usually takes some time to convert macros.
Copy file name to clipboardExpand all lines: _pages/plugins/bigstitcher/headless.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -96,6 +96,6 @@ to process another dataset with a different number of tiles headlessly:
96
96
97
97
After saving the macro, it can be run from any Terminal by starting Fiji in [Headless](/learn/headless) mode and passing the macro as well as a parameter string.
Copy file name to clipboardExpand all lines: _pages/scripting/headless.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,13 +9,13 @@ project: /software/imagej2
9
9
To start ImageJ2 headless mode, run (with the launcher appropriate for your system substituted):
10
10
11
11
```ssh
12
-
./ImageJ-linux64 --headless
12
+
./fiji --headless
13
13
```
14
14
15
15
By default, when ImageJ2 runs headlessly it acts like a one-off program: it will only perform the requested operations, then quit. To run a script headlessly, use:
{% include notice icon="warning" content='In many cases, it is necessary to enclose the entire list of key/value pairs in single quotes, to avoid shell expansion. See the following examples.' %}
@@ -33,21 +33,21 @@ print('Hello ' + name)
33
33
we could run this script with the command on [Linux](/platforms/linux):
Note that the `name` parameter must be enclosed in double quotes, since it is a string literal.
40
40
41
41
On [Windows](/platforms/windows) systems, single/double quotes might be inverted though, such that strings are enclosed in single quotes while the list of argument as well as the path to the py script are in double quotes.
Often headless mode is used to run many scripts in parallel that could result in huge numbers of server connections. Setting this parameter will prevent this issue. This parameter does not persist between launches and must be included every time server connections to update sites should be prevented.
85
85
86
86
If desired, the updater can be controlled in headless mode using the following commands to add an update site and update ImageJ.
87
87
88
88
```ssh
89
-
./ImageJ-linux64 --update add-update-site BAR https://sites.imagej.net/Tiago/
90
-
./ImageJ-linux64 --headless --update update
89
+
./fiji --update add-update-site BAR https://sites.imagej.net/Tiago/
90
+
./fiji --update update
91
91
```
92
92
93
93
You can also add multiple update sites in a single command line:
0 commit comments