The CommandLineTool implementing this is listed below:
class: CommandLineTool
id: rio
requirements:
NetworkAccess:
networkAccess: true
InlineJavascriptRequirement: {}
DockerRequirement:
dockerPull: ghcr.io/eoap/how-to/how-to-container:1.1.0
baseCommand: rio
arguments:
- info
- $(inputs.geotif)
inputs:
geotif:
type: string
stdout: message
outputs:
info:
type: string
outputBinding:
glob: message
loadContents: true
outputEval: $(self[0].contents)
The tool stdout is redirected to a temporary file named message
:
stdout: message
which is globbed and its content loaded into an output named info
info:
type: string
outputBinding:
glob: message
loadContents: true
outputEval: $(self[0].contents)
Execute the workflow, this returns:
INFO /opt/hostedtoolcache/Python/3.12.7/x64/bin/cwltool 3.1.20241112140730
INFO Resolved '../cwl/02-stdout/capture-stdout.cwl' to 'file:///home/runner/work/how-to/how-to/cwl/02-stdout/capture-stdout.cwl'
INFO [workflow ] start
INFO [workflow ] starting step step-info
INFO [step step-info] start
INFO [job step-info] /tmp/msh0fx6h$ docker \
run \
-i \
--mount=type=bind,source=/tmp/msh0fx6h,target=/eXJxuQ \
--mount=type=bind,source=/tmp/5hkmo23f,target=/tmp \
--workdir=/eXJxuQ \
--read-only=true \
--log-driver=none \
--user=1001:127 \
--rm \
--cidfile=/tmp/y7l2964d/20241211090555-244396.cid \
--env=TMPDIR=/tmp \
--env=HOME=/eXJxuQ \
ghcr.io/eoap/how-to/how-to-container:1.1.0 \
rio \
info \
https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/10/T/FK/2021/7/S2B_10TFK_20210713_0_L2A/TCI.tif > /tmp/msh0fx6h/message
INFO [job step-info] Max memory used: 44MiB
INFO [job step-info] completed success
INFO [step step-info] completed success
INFO [workflow ] completed success
INFO Final process status is success
The info
output is:
{
"info": "{\"blockxsize\": 1024, \"blockysize\": 1024, \"bounds\": [600000.0, 4390200.0, 709800.0, 4500000.0], \"colorinterp\": [\"red\", \"green\", \"blue\"], \"compress\": \"deflate\", \"count\": 3, \"crs\": \"EPSG:32610\", \"descriptions\": [null, null, null], \"driver\": \"GTiff\", \"dtype\": \"uint8\", \"height\": 10980, \"indexes\": [1, 2, 3], \"interleave\": \"pixel\", \"lnglat\": [-121.18160686746373, 40.1419732942866], \"mask_flags\": [[\"nodata\"], [\"nodata\"], [\"nodata\"]], \"nodata\": 0.0, \"res\": [10.0, 10.0], \"shape\": [10980, 10980], \"tiled\": true, \"transform\": [10.0, 0.0, 600000.0, 0.0, -10.0, 4500000.0, 0.0, 0.0, 1.0], \"units\": [null, null, null], \"width\": 10980}\n"
}
{
"blockxsize": 1024,
"blockysize": 1024,
"bounds": [
600000,
4390200,
709800,
4500000
],
"colorinterp": [
"red",
"green",
"blue"
],
"compress": "deflate",
"count": 3,
"crs": "EPSG:32610",
"descriptions": [
null,
null,
null
],
"driver": "GTiff",
"dtype": "uint8",
"height": 10980,
"indexes": [
1,
2,
3
],
"interleave": "pixel",
"lnglat": [
-121.18160686746373,
40.1419732942866
],
"mask_flags": [
[
"nodata"
],
[
"nodata"
],
[
"nodata"
]
],
"nodata": 0,
"res": [
10,
10
],
"shape": [
10980,
10980
],
"tiled": true,
"transform": [
10,
0,
600000,
0,
-10,
4500000,
0,
0,
1
],
"units": [
null,
null,
null
],
"width": 10980
}
Key points¶
- Use the
stdout
field to specify a filename to capture streamed output. - Load the contents of the specified filename