ImageJ headless mode

@ctrueden @imagejan @constantinpape
Is there a way to programmatically discover where Fiji has been started headless from the command line? My use case is that upon an error I want to terminate with System.exit( 1 ) such that the executing command line tool can see that there was an error. However in Fiji executing System.exit( 1 ) closes Fiji, which is not very nice :wink:
Or is there anyway another way of doing this? Maybe throw some error would also yield a proper return code on the command line?

@Christian_Tischer Use the isHeadless() method of UIService to check:

if (uiService.isHeadless()) {
  try {
    context.dispose();
  }
  finally {
    System.exit(1);
  }
}

Disposing the context first gives ImageJ services an opportunity to clean up (e.g. writing caches out to disk) before you shut down the JVM.

3 Likes