View Issue Details

IDProjectCategoryView StatusLast Update
0001455Slicer4Core: CLI infrastructurepublic2012-09-05 07:56
Reporterfedorov Assigned Tojcfr  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product VersionSlicer 4.0.0 
Target VersionSlicer 4.2.0Fixed in VersionSlicer 4.2.0 
Summary0001455: Launching CLI modules from command line
Description

It would be nice if CLI modules could be invoked without specifying the full path, like it was possible in Slicer3:

Slicer4 --launch Module

Right now it can only be done this way:

Slicer4 --launch ./plugins/Module

TagsNo tags attached.

Activities

fedorov

fedorov

2011-09-26 13:38

developer   ~0003119

The reason I would like this functionality to be there is I would like to launch a CLI plugin from another plugin written in C++. If Slicer knows about plugin paths, I can just do system(<plugin_name>), otherwise I don't know how to find that location, assuming user does not have to set Slicer_DIR. Let me know if there is a better way to do this ...

jcfr

jcfr

2011-09-28 14:34

administrator   ~0003131

Could you clarify what do you mean by "system(<plugin_name>)".

I understood you talk about the following command: http://www.cplusplus.com/reference/clibrary/cstdlib/system/

But I am not sure to understand what do you mean by <plugin_name>.

Considering the Threshold executable, does it means:
1) plugin_name -> Threshold
2) plugin_name -> /path/to/Threshold
3) plugin_name -> Slicer --launch Threshold
4) plugin_name -> Slicer --launch /path/to/Threshold
5) plugin_name -> /path/to/Slicer --launch Threshold
6) plugin_name -> /path/to/Slicer --launch /path/to/Threshold

6) works
4) works assuming the path containing the launcher is added to the PATH

Just to make sure, by an "other plugin written in C++", you mean an other CLI executable or a loadable module ?

fedorov

fedorov

2011-09-28 14:39

developer   ~0003132

By <plugin_name> I would like to have your option (1).

My usage scheme:

Slicer main app -----> launches cliPlugin1 (inherits environment from Slicer main application)
                                                -----> launches cliPlugin2 by &quot;system(cliPlugin2)&quot;
jcfr

jcfr

2011-09-28 14:49

administrator   ~0003133

Try to change line depicted by [1] into:

<APPLAUNCHER_DIR>/${Slicer_CLIMODULES_BIN_DIR}/<CMAKE_CFG_INTDIR>

Note: I just noticed that SlicerINSTALL should also be changed into Slicer_ in [2] and [3]

[1] https://github.com/Slicer/Slicer/blob/master/CMake/SlicerBlockCTKAppLauncherSettings.cmake#L160

[2] https://github.com/Slicer/Slicer/blob/master/CMake/SlicerBlockCTKAppLauncherSettings.cmake#L94

[3] https://github.com/Slicer/Slicer/blob/master/CMake/SlicerBlockCTKAppLauncherSettings.cmake#L100

fedorov

fedorov

2011-09-28 15:32

developer   ~0003134

JC, did the changes as you instructed:

Index: CMake/SlicerBlockCTKAppLauncherSettings.cmake

--- CMake/SlicerBlockCTKAppLauncherSettings.cmake (revision 18179)
+++ CMake/SlicerBlockCTKAppLauncherSettings.cmake (working copy)
@@ -91,13 +91,13 @@

if(Slicer_BUILD_CLI)
list(APPEND SLICER_LIBRARY_PATHS_BUILD

  • <APPLAUNCHER_DIR>/${Slicer_INSTALL_CLIMODULES_LIB_DIR}/<CMAKE_CFG_INTDIR>
  • <APPLAUNCHER_DIR>/${Slicer_CLIMODULES_BIN_DIR}/<CMAKE_CFG_INTDIR>
    )
    endif()

    if(Slicer_BUILD_QTLOADABLEMODULES)
    list(APPEND SLICER_LIBRARY_PATHS_BUILD

  • <APPLAUNCHER_DIR>/${Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR}/<CMAKE_CFG_INTDIR>
  • <APPLAUNCHER_DIR>/${Slicer_QTLOADABLEMODULES_BIN_DIR}/<CMAKE_CFG_INTDIR>
    )
    endif()

@@ -157,7 +157,7 @@

if(Slicer_BUILD_CLI)
list(APPEND SLICER_PATHS_BUILD

  • <APPLAUNCHER_DIR>/${Slicer_INSTALL_CLIMODULES_LIB_DIR}/<CMAKE_CFG_INTDIR>
  • <APPLAUNCHER_DIR>/${Slicer_CLIMODULES_BIN_DIR}/<CMAKE_CFG_INTDIR>
    )
    endif()

Recompiled (make from Slicer-build). When I look in Slicer-build/SlicerLauncherSettings.ini, there is this section now:

[Paths]
1\path=<APPLAUNCHER_DIR>/bin/.
2\path=/Users/fedorov/Slicer/Slicer4-SuperBuild/teem-build/bin/.
3\path=/Users/fedorov/local/bin
4\path=<APPLAUNCHER_DIR>/lib/Slicer-4.0/cli-modules/.
5\path=<APPLAUNCHER_DIR>/Slicer.app/Contents/lib/Slicer-4.0/qt-loadable-modules/.
6\path=/Users/fedorov/Slicer/Slicer4-SuperBuild/tcl-build/bin
size=6

However, the module is still not resolved:

[fedorov@bear Slicer-build] ls -la lib/Slicer-4.0/cli-modules/BRAINSFit
-rwxr-xr-x 1 fedorov staff 50176 Sep 21 19:28 lib/Slicer-4.0/cli-modules/BRAINSFit
[fedorov@bear Slicer-build] ./Slicer --launch BRAINSFit --help
Usage
Slicer [options]

Options
--launcher-help Display help
--launcher-verbose Verbose mode
--launch Specify the application to launch
--launcher-detach Launcher will NOT wait for the application to finish
--launcher-no-splash Hide launcher splash
--launcher-timeout Specify the time in second before the launcher kills the application. -1 means no timeout (default: -1)
--launcher-generate-template Generate an example of setting file
--designer Start Qt designer using Slicer plugins
--ddd Start ddd
--xterm Start xterm
--gdb Start gdb
error: Application does NOT exists [BRAINSFit]

jcfr

jcfr

2011-09-28 16:18

administrator   ~0003135

1) Regarding the LIBRARY_PATHS:

  • Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR should have been changed into Slicer_QTLOADABLEMODULES_LIB_DIR and NOT Slicer_QTLOADABLEMODULES_BIN_DIR

  • Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR should have been changed into Slicer_QTLOADABLEMODULES_LIB_DIR and NOT Slicer_QTLOADABLEMODULES_BIN_DIR

Looking at this more closely ... on linux, having the "_INSTALL" qualifier doesn't change anything.

2) Your test doesn't match the use case you previously described. Indeed, the launcher doesn't search the path. The use case described assumes you run a CLI either from Slicer or using "Slicer --launch /path/to/cli" and that given CLI executable will attempt to run an other cli using "system()"

3) Using system() from within a CLI executable should work if system() search the PATH. Does system() search the PATH env ?

4) We could also provide some utility function to return the full path of a given executable by searching the PATH. This could be done in the CTK launcher itself so that "Slicer --launch <CLIExecutableName>" works. And could also be done to retrieve the path of a cli executable before your execute system("CLIExecutableName")

fedorov

fedorov

2011-09-28 16:40

developer   ~0003136

(1) you are right

(2) you are correct again -- I took a shortcut to test this. system("CLIExecutableName") now works, my problem is resolved. Can you confirm the fix is committed to the trunk?

(4) I think for the future it would be nice to have "Slicer --launch "CLIExecutableName" working, to maintain backwards compatibility with Slicer3 batch scripts for one thing. But this is not in my critical path, not urgent.

Thanks a lot for the help!

fedorov

fedorov

2011-09-30 17:54

developer   ~0003152

fixed by JC in http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&amp;revision=18230

fedorov

fedorov

2011-11-10 13:18

developer   ~0003303

This does not work in packaged Slicer (as tested on Mac).

To reproduce:

1) load any 2 volumes into binary packaged Slicer

2) run the following from python console

p
{'tmpDirectory': '/home/fedorov/Trash', 'outputVolume': 'vtkMRMLScalarVolumeNode1', 'reportFileName': '/home/fedorov/Trash/rep.txt', 'baselineVolume': 'vtkMRMLScalarVolumeNode2', 'baselineSegmentationVolume': 'vtkMRMLScalarVolume2'}
mm = slicer.app.moduleManager()
plugin = mm.module('DemonsSegmentationMetric')
cliNode = None
cliNode = slicer.cli.run(plugin, cliNode, p, 1)

Error in the log:

ERROR: In /Users/fedorov/Slicer/Slicer4/Base/QTCLI/vtkSlicerCLIModuleLogic.cxx, line 1466
vtkSlicerCLIModuleLogic (0x13b5b0b70): Demons Registration: Segmentation-based Change Detection (SLOW) standard error:

sh: BRAINSDemonWarp: command not found
ERROR during demons registration

ERROR: In /Users/fedorov/Slicer/Slicer4/Base/QTCLI/vtkSlicerCLIModuleLogic.cxx, line 1492
vtkSlicerCLIModuleLogic (0x13b5b0b70): Demons Registration: Segmentation-based Change Detection (SLOW) completed with errors

Corresponding code from the DemonsSegmentationMetric that does not work:

https://github.com/fedorov/ChangeTrackerPy/blob/master/Metrics/DemonsSegmentation/DemonsSegmentationMetric.cxx#L38

ChrisG

ChrisG

2011-11-11 05:24

reporter   ~0003306

Doesn't work in revision 18672. Fixing this would make nipype support more robust. For more details see https://github.com/nipy/nipype/pull/218#issuecomment-2706681

fedorov

fedorov

2012-02-25 07:55

developer   ~0003726

from email to ChrisG Jan 11:

Hi Chris,

I talked to JC about this yesterday.

He says for certain reasons implementing "Slicer4 --launch <module
name>" is a bit tricky, but with the existing functionality you can
get the path of any module, you can then concatenate that path with
the name and use it in Slicer --launch.

Note that some modules are loaded as dynamic libraries, so you may
need to do some extra manipulations.

from Slicer python console:

slicer.modules.brainsfit.path
u'/Users/fedorov/Slicer/Slicer4-SuperBuild/Slicer-build/lib/Slicer-4.0/cli-modules/libBRAINSFitLib.dylib'
slicer.modules.brainsfit.name
u'BRAINSFit'

So then you can put name as the last component of the path, and pass
it to --launch.

Would this solution work for you?

Maybe somewhere in Nipype internally, if the user tries to call Slicer
module, you can detect it and do the magic under the hood. Let us
know.

jcfr

jcfr

2012-04-25 17:38

administrator   ~0004080

See https://github.com/commontk/AppLauncher/issues/6

jcfr

jcfr

2012-07-17 21:03

administrator   ~0005184

Fixed in https://github.com/jcfr/AppLauncher/commit/a02b1a3cacdd0a40f795547c792768659161

jcfr

jcfr

2012-07-17 21:03

administrator   ~0005185

Last edited: 2012-07-17 21:05

Fixed in https://github.com/jcfr/AppLauncher/commit/a02b1a3cacdd0a40f795547c792768659161

The next release of the Launcher will allow to run program in the PATH using:

Slicer --launch foo (or Slicer --launch foo.exe)

or

Slicer --launch bar/foo

On windows, if extension is not specified, it will be automatically appended.

fedorov

fedorov

2012-07-21 16:27

developer   ~0005213

JC, when is this next release of Launcher going to be integrated with Slicer?

jcfr

jcfr

2012-07-24 19:36

administrator   ~0005229

Fixed in r20684
See http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&amp;revision=20684

fedorov

fedorov

2012-07-25 05:12

developer   ~0005232

Trying to launch CastScalarVolume (which exists):

[fedorov@gridftp-spl Slicer-build]$ ls lib/Slicer-4.1/cli-modules | grep CastScalarVolume
CastScalarVolume
libCastScalarVolumeLib.so

directly by "--launch CastScalarVolume" there's error "Application does NOT exists [CastScalarVolume]":

[fedorov@gridftp-spl Slicer-build]$ ./Slicer --launch CastScalarVolume --help
Usage
Slicer [options]

Options
--launcher-help Display help
--launcher-version Show launcher version information
--launcher-verbose Verbose mode
--launch Specify the application to launch
--launcher-detach Launcher will NOT wait for the application to finish
--launcher-no-splash Hide launcher splash
--launcher-timeout Specify the time in second before the launcher kills the application. -1 means no timeout (default: -1)
--launcher-dump-environment Launcher will print environment variables to be set, then exit
--launcher-additional-settings Additional settings file to consider
--launcher-generate-template Generate an example of setting file
--xterm Start xterm
--gdb Start gdb
error: Application does NOT exists [CastScalarVolume]
Usage
Slicer [options]

Options
--launcher-help Display help
--launcher-version Show launcher version information
--launcher-verbose Verbose mode
--launch Specify the application to launch
--launcher-detach Launcher will NOT wait for the application to finish
--launcher-no-splash Hide launcher splash
--launcher-timeout Specify the time in second before the launcher kills the application. -1 means no timeout (default: -1)
--launcher-dump-environment Launcher will print environment variables to be set, then exit
--launcher-additional-settings Additional settings file to consider
--launcher-generate-template Generate an example of setting file
--xterm Start xterm
--gdb Start gdb

If I --launch with the full path, it works:

[fedorov@gridftp-spl Slicer-build]$ ./Slicer --launch ./lib/Slicer-4.1/cli-modules/CastScalarVolume --help
Usage
Slicer [options]

Options
--launcher-help Display help
--launcher-version Show launcher version information
--launcher-verbose Verbose mode
--launch Specify the application to launch
--launcher-detach Launcher will NOT wait for the application to finish
--launcher-no-splash Hide launcher splash
--launcher-timeout Specify the time in second before the launcher kills the application. -1 means no timeout (default: -1)
--launcher-dump-environment Launcher will print environment variables to be set, then exit
--launcher-additional-settings Additional settings file to consider
--launcher-generate-template Generate an example of setting file
--xterm Start xterm
--gdb Start gdb
Usage
Slicer [options]

Options
--launcher-help Display help
--launcher-version Show launcher version information
--launcher-verbose Verbose mode
--launch Specify the application to launch
--launcher-detach Launcher will NOT wait for the application to finish
--launcher-no-splash Hide launcher splash
--launcher-timeout Specify the time in second before the launcher kills the application. -1 means no timeout (default: -1)
--launcher-dump-environment Launcher will print environment variables to be set, then exit
--launcher-additional-settings Additional settings file to consider
--launcher-generate-template Generate an example of setting file
--xterm Start xterm
--gdb Start gdb

USAGE:

./lib/Slicer-4.1/cli-modules/CastScalarVolume [--returnparameterfile
<std::string>]
[--processinformationaddress
<std::string>] [--xml] [--echo] [-t
<Char|UnsignedChar|Short
|UnsignedShort|Int|UnsignedInt
|Float|Double>] [--] [--version]
[-h] <std::string> <std::string>

Where:

--returnparameterfile <std::string>
Filename in which to write simple return parameters (int, float,
int-vector, etc.) as opposed to bulk return parameters (image,
geometry, transform, measurement, table).

--processinformationaddress <std::string>
Address of a structure to store process information (progress, abort,
etc.). (default: 0)

--xml
Produce xml description of command line arguments (default: 0)

--echo
Echo the command line arguments (default: 0)

-t <Char|UnsignedChar|Short|UnsignedShort|Int|UnsignedInt|Float|Double>,
--type <Char|UnsignedChar|Short|UnsignedShort|Int|UnsignedInt|Float
|Double>
Type for the new output volume. (default: UnsignedChar)

--, --ignore_rest
Ignores the rest of the labeled arguments following this flag.
...

jcfr

jcfr

2012-07-27 15:16

administrator   ~0005289

The problem is understood and captured in the following CTKAppLauncher issue: https://github.com/commontk/AppLauncher/issues/31

jcfr

jcfr

2012-09-04 10:13

administrator   ~0005950

Solution in the work: https://github.com/jcfr/AppLauncher/commit/fadfd458952aaeffa07834ee61cdd661e3fd90d3

Still need to fix on issue preventing the added test from passing on windows.

jcfr

jcfr

2012-09-04 13:53

administrator   ~0005963

New launcher released (0.1.8), fixed in r20925
See http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&amp;revision=20925

fedorov

fedorov

2012-09-05 07:56

developer   ~0005972

I confirmed the issues is resolved on all platforms.

A related issue is that there is no console output on Windows.

Issue History

Date Modified Username Field Change
2011-09-25 18:51 fedorov New Issue
2011-09-25 18:53 finetjul Status new => assigned
2011-09-25 18:53 finetjul Assigned To => jcfr
2011-09-26 13:38 fedorov Note Added: 0003119
2011-09-28 14:34 jcfr Note Added: 0003131
2011-09-28 14:39 fedorov Note Added: 0003132
2011-09-28 14:49 jcfr Note Added: 0003133
2011-09-28 15:32 fedorov Note Added: 0003134
2011-09-28 16:18 jcfr Note Added: 0003135
2011-09-28 16:40 fedorov Note Added: 0003136
2011-09-30 17:54 fedorov Note Added: 0003152
2011-09-30 17:54 fedorov Status assigned => closed
2011-09-30 17:54 fedorov Resolution open => fixed
2011-11-10 13:18 fedorov Note Added: 0003303
2011-11-10 13:18 fedorov Status closed => feedback
2011-11-10 13:18 fedorov Resolution fixed => reopened
2011-11-11 05:24 ChrisG Note Added: 0003306
2012-02-25 07:55 fedorov Note Added: 0003726
2012-04-25 17:38 jcfr Note Added: 0004080
2012-04-26 13:17 jcfr Status feedback => assigned
2012-07-17 21:03 jcfr Note Added: 0005184
2012-07-17 21:03 jcfr Note Added: 0005185
2012-07-17 21:05 jcfr Note Edited: 0005185
2012-07-21 16:27 fedorov Note Added: 0005213
2012-07-24 19:35 jcfr Target Version => Slicer 4.2.0 - October 1st 2012
2012-07-24 19:36 jcfr Note Added: 0005229
2012-07-24 19:36 jcfr Status assigned => resolved
2012-07-24 19:36 jcfr Fixed in Version => Slicer 4.2.0 - October 1st 2012
2012-07-24 19:36 jcfr Resolution reopened => fixed
2012-07-25 05:12 fedorov Note Added: 0005232
2012-07-25 05:12 fedorov Status resolved => feedback
2012-07-25 05:12 fedorov Resolution fixed => reopened
2012-07-27 15:16 jcfr Note Added: 0005289
2012-07-27 15:16 jcfr Status feedback => assigned
2012-09-04 10:13 jcfr Note Added: 0005950
2012-09-04 13:53 jcfr Note Added: 0005963
2012-09-04 13:53 jcfr Status assigned => resolved
2012-09-04 13:53 jcfr Resolution reopened => fixed
2012-09-05 07:56 fedorov Note Added: 0005972
2012-09-05 07:56 fedorov Status resolved => closed