# cmdLineTask returns status to the shell

**URL:** <https://www.rubin.community/t/cmdlinetask-returns-status-to-the-shell/2098>\
**Category:** Data Management\
**Tags:** cmdlinetask\
**Created:** [July 20, 2017, 7:02pm UTC](https://www.rubin.community/t/cmdlinetask-returns-status-to-the-shell/2098 "2017-07-20T19:02:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RHL](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/rhl/32/25_2.png) [@RHL](https://www.rubin.community/u/RHL)\
**Post date:** [July 20, 2017, 7:02pm UTC](https://www.rubin.community/t/cmdlinetask-returns-status-to-the-shell/2098/1 "2017-07-20T19:02:07Z")

</div>

Just a quick note that the long-festering DM-4141 is finally fixed; if I did it right, command line tasks (including calibration tasks in pipe\_drivers) should now return proper unix error codes upon failure.

More completely, the tasks return the number of dataRef that failed (so if nothing fails you get 0, which unix considers as success).

The error exit comes from `ParseAndRun` so the calling script (usually in bin) will _not_ see the task return; if you want to avoid this you can specify `--noExit`, but then you’ll have to handle the errors yourself.

---

<div class="post-metadata">

**Author:** ![jsick](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/jsick/32/672_2.png) [@jsick](https://www.rubin.community/u/jsick)\
**Post date:** [July 20, 2017, 7:32pm UTC](https://www.rubin.community/t/cmdlinetask-returns-status-to-the-shell/2098/2 "2017-07-20T19:32:40Z")

</div>

I don’t know a specific solution yet, but I have the feeling there are usability issues with the name of this new argument `--noExit` and the help string:

> Do not exit even upon failure (i.e. return a struct to the calling script)

I think it’s that the flag/help string are breaking the encapsulation of the command line program and requiring the user to know the difference between the script itself and the `ParseAndRun` internals. The user certainly wouldn’t know about the `struct`.

Can we think of a better way to describe/document this feature?

---

<div class="post-metadata">

**Author:** ![RHL](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/rhl/32/25_2.png) [@RHL](https://www.rubin.community/u/RHL)\
**Post date:** [July 20, 2017, 8:02pm UTC](https://www.rubin.community/t/cmdlinetask-returns-status-to-the-shell/2098/3 "2017-07-20T20:02:30Z")

</div>

I don’t think anyone will ever want to use this feature. What’s your concern here?

---

<div class="post-metadata">

**Author:** ![jsick](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/jsick/32/672_2.png) [@jsick](https://www.rubin.community/u/jsick)\
**Post date:** [July 20, 2017, 8:32pm UTC](https://www.rubin.community/t/cmdlinetask-returns-status-to-the-shell/2098/4 "2017-07-20T20:32:54Z")

</div>

Maybe `--noExitStatus` for the argument name?

---

<div class="post-metadata">

**Author:** ![RHL](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/rhl/32/25_2.png) [@RHL](https://www.rubin.community/u/RHL)\
**Post date:** [July 20, 2017, 9:20pm UTC](https://www.rubin.community/t/cmdlinetask-returns-status-to-the-shell/2098/5 "2017-07-20T21:20:40Z")

</div>

Jonathan and I discussed this on slack (after I fixed master which I’d broken – my excuse for being terse here). To quote me:

> I only added it because almost all the `cmdLineTask` scripts run the python from a boilerplate script in bin which ignores the return values; because they basically don’t expect the Task to return it seemed OK to call exit within the Task rather than delegating to the highest level of the calling tree (which would have required changes to _every_ driver script). However, calling `sys.exit` is usually a rude thing to do so I felt that I had to provide a way to bypass it

So `--noExitStatus` isn’t quite right; it’s preventing `parseAndRun` from exiting so I still prefer `--noExit`

---

<div class="post-metadata">

**Author:** ![jjt](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/jjt/32/125_2.png) [@jjt](https://www.rubin.community/u/jjt)\
**Post date:** [July 21, 2017, 3:40pm UTC](https://www.rubin.community/t/cmdlinetask-returns-status-to-the-shell/2098/6 "2017-07-21T15:40:54Z")

</div>

How about --sartre?
