# Returning a vector from CLI module

**URL:** <https://discourse.slicer.org/t/returning-a-vector-from-cli-module/8359>\
**Category:** Development\
**Created:** [September 10, 2019, 9:01am UTC](https://discourse.slicer.org/t/returning-a-vector-from-cli-module/8359 "2019-09-10T09:01:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![fpsiddiqui91](https://avatars.discourse-cdn.com/v4/letter/f/53a042/32.png) [@fpsiddiqui91](https://discourse.slicer.org/u/fpsiddiqui91)\
**Post date:** [September 10, 2019, 9:01am UTC](https://discourse.slicer.org/t/returning-a-vector-from-cli-module/8359/1 "2019-09-10T09:01:11Z")

</div>

Hello Developers.

I am developing a CLI module and calling it from my scripted module using “slicer.cli.run” . I can parse the arguments from my scripted module to CLI module but I failed to get the returning arguments from my CLI module.

I am trying to copy fudicial registration module but unfortunately I wasn’t able to get the returning argument in my scripted module. I am missing simething, it might be very basic, but I have wasted alot of time in it.

My XML is:

```
<?xml version="1.0" encoding="utf-8"?>

```

 Examples CLI\_test 0.0.1 http://www.example.com/Slicer/Modules/CLI\_test Slicer FirstName LastName (Institution), FirstName LastName (Institution) This work was partially funded by NIH grant NXNNXXNNNNNN-NNXN IO sigmas sigmas s output

```
  <label>Sigmas</label>
  <description><![CDATA[A double value (in units of mm) passed to the algorithm]]></description>
     </float-vector>

<double>
  <name>rms</name>
  <longflag>rms</longflag>
  <description><![CDATA[Display RMS Error.]]></description>
  <flag>R</flag>
  <label>RMS Error</label>
  <channel>output</channel>
  <default>0.1</default>
</double>

```

The part of updating rms value in my CLI .cpp code is:

rms=42.0 ;  
std::ofstream rts;  
rts.open(returnParameterFile.c\_str() );  
rts \<\< “rms=” \<\< rms \<\< std::endl;  
rts.close();

I dont know how to get this “rms” value in my scripted module (python code). Thank you in advance

---

<div class="post-metadata">

**Author:** ![fpsiddiqui91](https://avatars.discourse-cdn.com/v4/letter/f/53a042/32.png) [@fpsiddiqui91](https://discourse.slicer.org/u/fpsiddiqui91)\
**Post date:** [September 10, 2019, 11:44am UTC](https://discourse.slicer.org/t/returning-a-vector-from-cli-module/8359/2 "2019-09-10T11:44:31Z")

</div>

Just to be clear, If I run my CLI module as standalone program it does generate an output text file, my question is, how can I get the output if I call my CLI from scripted module with slicer.cli.run command.

Thank you.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 10, 2019, 12:59pm UTC](https://discourse.slicer.org/t/returning-a-vector-from-cli-module/8359/3 "2019-09-10T12:59:36Z")

</div>

Return values are stored in the parameter node and you can retrieve it using `GetParameterAsString()` method. For example:

```python
parameterNode = slicer.util.getNode('Execution Model Tour')
returnedRmsValue = float(parameterNode.GetParameterAsString('rms'))

```

---

<div class="post-metadata">

**Author:** ![fpsiddiqui91](https://avatars.discourse-cdn.com/v4/letter/f/53a042/32.png) [@fpsiddiqui91](https://discourse.slicer.org/u/fpsiddiqui91)\
**Post date:** [September 10, 2019, 1:16pm UTC](https://discourse.slicer.org/t/returning-a-vector-from-cli-module/8359/4 "2019-09-10T13:16:20Z")

</div>

Thank you for you reply Andras, I have tried this command, the problem is my ‘rms’ variable doesn’t get updated. its just returning the same initial value.

Ideally, inital rms value should go into my CLI module , it should get updated, and I should get the updated variable.

this is the python code from where I am calling my CLI

```
module = slicer.modules.cli_test

rms=5.0
a=(np.random.randint(0, 100, size=(30, 10, 2)) ).tolist()

cliParams = {
  'sigmas' : a,
  'rms' : rms,

}

cliNode = slicer.cli.run(module, None, cliParams, wait_for_completion=True)

returnedRmsValue = float(cliNode.GetParameterAsString('rms'))
print(returnedRmsValue)

```

The returned RMS value should be 49, but it is still giving 5.  
Am I missing something?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 10, 2019, 1:26pm UTC](https://discourse.slicer.org/t/returning-a-vector-from-cli-module/8359/5 "2019-09-10T13:26:41Z")

</div>

A parameter can be either input or output, defined by the `channel` element. For example, `<channel>output</channel>` means an output parameter.

---

<div class="post-metadata">

**Author:** ![fpsiddiqui91](https://avatars.discourse-cdn.com/v4/letter/f/53a042/32.png) [@fpsiddiqui91](https://discourse.slicer.org/u/fpsiddiqui91)\
**Post date:** [September 10, 2019, 1:28pm UTC](https://discourse.slicer.org/t/returning-a-vector-from-cli-module/8359/6 "2019-09-10T13:28:55Z")

</div>

yes, I have defined the parameter as output. (xml attached in my first post). Even then it is not updating.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 10, 2019, 1:33pm UTC](https://discourse.slicer.org/t/returning-a-vector-from-cli-module/8359/7 "2019-09-10T13:33:42Z")

</div>

It works for me with the ExecutionModelTour test module. See how to correctly write output parameters here:

> <https://github.com/Slicer/Slicer/blob/e091a2b016eef4a621fce1dfecc6faa7f6433b51/Modules/CLI/ExecutionModelTour/ExecutionModelTour.cxx#L188-L198>

There are no whitespaces in your code above, maybe that breaks the output file parsing.

---

<div class="post-metadata">

**Author:** ![fpsiddiqui91](https://avatars.discourse-cdn.com/v4/letter/f/53a042/32.png) [@fpsiddiqui91](https://discourse.slicer.org/u/fpsiddiqui91)\
**Post date:** [September 10, 2019, 1:45pm UTC](https://discourse.slicer.org/t/returning-a-vector-from-cli-module/8359/8 "2019-09-10T13:45:05Z")

</div>

Thank you fro your response Andras, I have tried the exact same thing. Even hardcoded the text, it is still returning the same value.

Am I making any mistake in calling a CLI?

```
cliNode = slicer.cli.run(module, None, cliParams, wait_for_completion=True)

```

parameters being:

```
rms=5.0
a=(np.random.randint(0, 100, size=(30, 10, 2)) ).tolist()
sigmaout=23.0
cliParams = {
  'sigmas' : a,
  'rms' : rms,
  'sigmaout' : sigmaout

}
```

---

<div class="post-metadata">

**Author:** ![fpsiddiqui91](https://avatars.discourse-cdn.com/v4/letter/f/53a042/32.png) [@fpsiddiqui91](https://discourse.slicer.org/u/fpsiddiqui91)\
**Post date:** [September 10, 2019, 2:33pm UTC](https://discourse.slicer.org/t/returning-a-vector-from-cli-module/8359/9 "2019-09-10T14:33:31Z")

</div>

Thank you Andras, it worked. there were some other problems. Thank you for your help
