Skip to content

Commit c8b2834

Browse files
committed
Update headless-related docs for Jaunch
1 parent 46bf7f6 commit c8b2834

File tree

3 files changed

+30
-36
lines changed

3 files changed

+30
-36
lines changed

_pages/learn/headless.md

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,33 @@ However, it acquired [macro](/scripting/macro) capabilities, a [batch mode](/scr
1010

1111
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.
1212

13-
# `--headless` mode
13+
## `--headless` mode
1414

1515
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.
1616

1717
**Shortcoming:** There are plugins which are even more bound to a GUI than
1818
ImageJ is. Naturally, these plugins will still try to instantiate GUI
1919
elements when being called in headless mode, failing.
2020

21-
## Running scripts in headless mode
21+
### Running scripts in headless mode
2222

2323
Please see the [headless scripting guide](/scripting/headless).
2424

25-
## Running macros in headless mode
25+
### Running macros in headless mode
2626

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

2929
```shell
30-
ImageJ --headless --console -macro path-to-Macro.ijm
30+
./fiji --headless -macro path-to-Macro.ijm
3131
```
32-
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.
3733

3834
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.
3935

40-
4136
You can even pass parameters to the macro; e.g.:
4237

4338
```shell
44-
./ImageJ-win64.exe --headless --console -macro ./RunBatch.ijm 'folder=../folder1 parameters=a.properties output=../samples/Output'
39+
./fiji --headless -macro ./RunBatch.ijm 'folder=../folder1 parameters=a.properties output=../samples/Output'
4540
```
4641

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

6055
{% 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.' %}
6156

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
6459
- `Table.Rename("oldTitle", "newTitle")`
6560

66-
6761
{% capture historical-note %}
6862
Headless support was originally a branch in [ImageJA](/libs/imageja); it worked
6963
by putting rewritten versions of three core ImageJ classes into a file called
@@ -79,8 +73,7 @@ launching ImageJ from the command line.
7973
{% endcapture %}
8074
{% include aside title="Historical note" content=historical-note %}
8175

82-
83-
# Why is `--headless` needed?
76+
## Why is `--headless` needed?
8477

8578
Java *does* support a headless mode via the `java.awt.headless` property; setting this property to `true` enables it.
8679

@@ -90,16 +83,17 @@ Since ImageJ was devised as a desktop application, everything -- including macro
9083

9184
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.
9285

93-
# Other solutions
94-
## Xvfb virtual desktop
86+
## Other solutions
87+
88+
### Xvfb virtual desktop
9589

9690
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.
9791

9892
**Advantage:** No run-time patching is required.
9993

10094
**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.
10195

102-
### Examples
96+
#### Examples
10397

10498
Here are a couple of simple examples.
10599

@@ -109,7 +103,7 @@ Passing direct arguments:
109103
$ cat hello.js
110104
importClass(Packages.ij.IJ);
111105
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
113107
hello Emerson
114108
```
115109

@@ -120,7 +114,7 @@ $ cat hello-with-params.js
120114
// @String name
121115
importClass(Packages.ij.IJ);
122116
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"'
124118
hello Emerson
125119
```
126120

@@ -143,6 +137,6 @@ wait # waits until all 'program' processes are finished
143137

144138
See also [this post on the ImageJ mailing list](https://list.nih.gov/cgi-bin/wa.exe?A2=IMAGEJ;5ace1ed0.1508).
145139

146-
## Rewriting as scripts or plugins
140+
### Rewriting as scripts or plugins
147141

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

_pages/plugins/bigstitcher/headless.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,6 @@ to process another dataset with a different number of tiles headlessly:
9696

9797
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.
9898

99-
` /path/to/fiji/ImageJ-linux64 --headless --console -macro /path/to/macro/bigStitcherBatch.ijm "/path/to/data 2 3"`
99+
` /path/to/Fiji/fiji --headless -macro /path/to/macro/bigStitcherBatch.ijm "/path/to/data 2 3"`
100100

101101
Go back to the [main page](/plugins/bigstitcher#documentation)

_pages/scripting/headless.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ project: /software/imagej2
99
To start ImageJ2 headless mode, run (with the launcher appropriate for your system substituted):
1010

1111
```ssh
12-
./ImageJ-linux64 --headless
12+
./fiji --headless
1313
```
1414

1515
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:
1616

1717
```ssh
18-
./ImageJ-linux64 --headless --run path/to/script [key1=value1,key2=value2,...]
18+
./fiji --headless --run path/to/script [key1=value1,key2=value2,...]
1919
```
2020

2121
{% 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)
3333
we could run this script with the command on [Linux](/platforms/linux):
3434

3535
```ssh
36-
./ImageJ-linux64 --headless --run hello.py 'name="Mr Kraken"'
36+
./fiji --headless --run hello.py 'name="Mr Kraken"'
3737
```
3838

3939
Note that the `name` parameter must be enclosed in double quotes, since it is a string literal.
4040

4141
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.
4242

4343
```ssh
44-
ImageJ-win64.exe --headless --run "PathTo/hello.py" "name='Mr Kraken'"
44+
fiji --headless --run "PathTo/hello.py" "name='Mr Kraken'"
4545
```
4646

4747
On [macOS](/platforms/macos) systems, the command can run in with the same quoting as on Linux:
4848

4949
```ssh
50-
./ImageJ-macosx --headless --run hello.py 'name="Mr Kracken"'
50+
./fiji --headless --run hello.py 'name="Mr Kracken"'
5151
```
5252

5353
## Multiple parameters
@@ -63,37 +63,37 @@ print('Hello ' + name1 + " and " + name2)
6363
then these are filled by using a comma-separated list of parameter pairs—e.g.:
6464

6565
```ssh
66-
./ImageJ-linux64 --headless --run hello.py 'name1="Mr",name2="Mrs Kraken"'
66+
./fiji --headless --run hello.py 'name1="Mr",name2="Mrs Kraken"'
6767
```
6868

6969
Similarly for Windows (again respect single/double quotes) or macOS,
7070

7171
```ssh
72-
ImageJ-win64.exe --headless --run "PathTo/hello.py" "name1='Mr', name2='Kraken'"
73-
./ImageJ-macosx --headless --run hello.py 'name1="Mr",name2="Mrs Kraken"'
72+
.\fiji --headless --run "PathTo/hello.py" "name1='Mr', name2='Kraken'"
73+
.\fiji --headless --run hello.py 'name1="Mr",name2="Mrs Kraken"'
7474
```
7575

7676
## Controlling the Updater
7777

7878
To prevent unnecessary server connections to update sites in headless mode you can set the `imagej.updater.disableAutocheck` java parameter `true`:
7979

8080
```ssh
81-
./ImageJ-linux64 -Dimagej.updater.disableAutocheck=true -- --headless --run hello.py 'name="Mr Kraken"'
81+
./fiji -Dimagej.updater.disableAutocheck=true -- --headless --run hello.py 'name="Mr Kraken"'
8282
```
8383

8484
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.
8585

8686
If desired, the updater can be controlled in headless mode using the following commands to add an update site and update ImageJ.
8787

8888
```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
9191
```
9292

9393
You can also add multiple update sites in a single command line:
9494

9595
```ssh
96-
./ImageJ-win64.exe --update add-update-sites "BAR" "https://sites.imagej.net/Tiago/" "IJPB-plugins" "https://sites.imagej.net/IJPB-plugins/"
96+
./fiji --update add-update-sites "BAR" "https://sites.imagej.net/Tiago/" "IJPB-plugins" "https://sites.imagej.net/IJPB-plugins/"
9797
```
9898

9999
Go to the updater section to get the [complete list of available commands](/plugins/updater).

0 commit comments

Comments
 (0)