# Creating a temporary directory at runtime

**URL:** <https://cwl.discourse.group/t/creating-a-temporary-directory-at-runtime/24>\
**Category:** CWL Questions\
**Created:** [August 19, 2019, 7:26pm UTC](https://cwl.discourse.group/t/creating-a-temporary-directory-at-runtime/24 "2019-08-19T19:26:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ionox0](https://yyz2.discourse-cdn.com/free1/user_avatar/cwl.discourse.group/ionox0/32/18_2.png) [@ionox0](https://cwl.discourse.group/u/ionox0)\
**Post date:** [August 19, 2019, 7:26pm UTC](https://cwl.discourse.group/t/creating-a-temporary-directory-at-runtime/24/1 "2019-08-19T19:26:48Z")

</div>

Which of these methods is preferred to create a temporary directory to use in \_JAVA\_OPTS during a workflow?

Option 1 - Create in a separate step and pass to tool:

```
cwlVersion: v1.0

class: CommandLineTool

requirements:
  - class: InlineJavascriptRequirement
  - class: InitialWorkDirRequirement
    listing:
      - entryname: empty_dir
        entry: "$({class: 'Directory', listing: []})"
        writable: true

arguments: [touch, empty_dir/placeholder]

inputs: []

outputs:
  empty_dir:
    type: Directory
    outputBinding:
      glob: empty_dir

```

Option 2 - Create with expression inside of tool itself:

```
cwlVersion: v1.0

class: CommandLineTool

arguments:
- java
- -Xmx50g
- -Djava.io.tmpdir=$(runtime.tmpdir)
- -jar
- abra.jar

requirements:
  InlineJavascriptRequirement: {}

inputs:

  working_directory:
    type: Directory?
    inputBinding:
      prefix: --tmpdir
      valueFrom: $(runtime.tmpdir)
```

---

<div class="post-metadata">

**Author:** ![mrc](https://yyz2.discourse-cdn.com/free1/user_avatar/cwl.discourse.group/mrc/32/3_2.png) [@mrc](https://cwl.discourse.group/u/mrc)\
**Post date:** [August 22, 2019, 6:28pm UTC](https://cwl.discourse.group/t/creating-a-temporary-directory-at-runtime/24/2 "2019-08-22T18:28:52Z")

</div>

Option 3 (slight tweak on option 2):

```auto
cwlVersion: v1.0

class: CommandLineTool

arguments:
- java
- -Xmx50g
- -Djava.io.tmpdir=$(runtime.tmpdir)
- -jar
- abra.jar
- prefix: --tmpdir
  valueFrom: $(runtime.tmpdir)
  

inputs: []

```

(The `InlineJavascriptRequirement` isn’t required, those are just plain CWL Parameter References.)

Portability bonus: use the classname of the main entrypoint for `abra.jar` on the command line instead of `-jar abra.jar` combined with updating your container/environement to put the jar in the `CLASSPATH`
