Skip to content

Commit

Permalink
output results for run() along with exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
dmachi committed Jan 24, 2024
1 parent 7f8c357 commit 67ea105
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
10 changes: 6 additions & 4 deletions docs/examples/exit-from-run/README.md
Expand Up @@ -8,16 +8,18 @@ This should be built from the root of the repository as follows:

The force_fail app returns exit code 155
```
# apptainer run scif.sif run force_fail ; echo "Out: $?"
$ apptainer run scif.sif run force_fail ; echo "Exit Code: $?";
[force_fail] executing /bin/bash /scif/apps/force_fail/scif/runscript
Calling exit 155
ERROR Return code 155
Out: 155
Exit Code: 155
```

The 'success' app returns exit code 0

```
$ apptainer run scif.sif run success ; echo "Out: $?"
$ apptainer run scif.sif run success ; echo "Exit Code: $?";
[success] executing /bin/bash /scif/apps/success/scif/runscript
Out: 0
Running successfully
Exit Code: 0
```
2 changes: 1 addition & 1 deletion docs/examples/exit-from-run/apptainer.def
Expand Up @@ -15,5 +15,5 @@ From: continuumio/miniconda3
# Install SCIF
cd /opt/scif
/opt/conda/bin/pip install setuptools
/opt/conda/bin/pip install -e .
/opt/conda/bin/pip install .
scif install /recipe.scif
2 changes: 1 addition & 1 deletion docs/examples/exit-from-run/recipe.scif
Expand Up @@ -3,5 +3,5 @@ echo "Calling exit 155"
exit 155

%apprun success
echo "Running succes"
echo "Running successfully"
exit 0
18 changes: 8 additions & 10 deletions scif/main/commands.py
Expand Up @@ -16,7 +16,7 @@
import locale
import sys
import os

import subprocess

def _exec(self, app=None, interactive=False, exit=False):
"""exec is the underlying driver of both run and exec, taking a final
Expand Down Expand Up @@ -88,14 +88,12 @@ def _exec(self, app=None, interactive=False, exit=False):
sys.exit(result["return_code"])
else:
os.system("".join(cmd))

else:
for line in os.popen(cmd):
try:
print(line.rstrip())
except:
print(line.rstrip().encode(loc))

cmd = cmd.split(" ")
result = self._run_command(
cmd=cmd, spinner=False, quiet=False
)
sys.exit(result["return_code"])

def execute(self, app, cmd=None, args=None):
"""execute a command in the context of an app. This means the following:
Expand Down Expand Up @@ -163,6 +161,7 @@ def run(self, app=None, args=None):
args: a list of one or more additional arguments to pass to runscript
"""
interactive=False
config = self.app(app)
if "apprun" not in config:
bot.debug("%s does not have a runscript." % app)
Expand All @@ -173,8 +172,7 @@ def run(self, app=None, args=None):
# updates environment
# sets entrypoint
# sets entryfolder

return self._exec(app, interactive=True, exit=True)
return self._exec(app, interactive=interactive)


def test(self, app=None, args=None):
Expand Down

0 comments on commit 67ea105

Please sign in to comment.