Skip to content

How to capture the stdout

Questions

  • How do I capture the standard output stream of a command?

Objectives

  • Learn how to capture streamed output from a tool.

CWL

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
cwlVersion: v1.0

$graph:
- class: Workflow
  id: main

  inputs:

    tif: 
      type: string

  outputs:

    info: 
      outputSource: gdal-info/info
      type: string

  steps:

    gdal-info:

      in: 
        tif: tif

      out: 
      - info

      run:
        "#gdal"

- class: CommandLineTool

  id: gdal

  requirements:
    InlineJavascriptRequirement: {}
    EnvVarRequirement:
      envDef:
        PROJ_LIB: /srv/conda/envs/notebook/share/proj
  hints:
    DockerRequirement: 
      dockerPull: docker.io/osgeo/gdal  

  baseCommand: gdalinfo

  stdout: message 

  arguments: 
  - valueFrom: |
        ${ if (inputs.tif.startsWith("http")) {
             return "/vsicurl/" + inputs.tif; 
           } else { 
             return inputs.tif;
           } 
        }

  inputs:

    tif:
      type: string

  outputs:

    info: 
      type: Any
      outputBinding:
        glob: message
        loadContents: true
        outputEval:  $( self[0].contents )

Parameters

tif: /vsicurl/https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/53/H/PA/2021/7/S2B_53HPA_20210723_0_L2A/B8A.tif

Key points

  • Use the stdout field to specify a filename to capture streamed output.

  • The corresponding output parameter must have type: stdout.