I'm trying to create a file in the processes temporary directory that is checked by nextflow for output using the native scripting language (Groovy) of nextflow.
Here is a minimal example:
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
process test {
echo true
output:
file('createMe')
exec:
path = 'createMe'
println path
output = file(path)
output.append('exemplary file content')
}
workflow {
test()
}
Simply creating the file in the current directory would work when using python as the scripting language, but here it fails with this message:
Error executing process > 'test'
Caused by:
Missing output file(s) `createMe` expected by process `test`
Source block:
path = 'createMe'
println path
output = file(path)
output.append('exemplary file content')
Work dir:
/home/some_user/some_path/work/89/915376cbedb92fac3e0a9b18536809
Tip: view the complete command output by changing to the process work dir and entering the command `cat .command.out`
I also tried to set the path to workDir + '/createMe'
, but the actual working directory seems to be a subdirectory of that path.
There was actually an issue (#2628) opened a few days ago regarding this exact behavior. The solution is to use task.workDir
to specify the task work directory:
This is caused by the fact the relative path is always resolved by the Jvm against the main current launching directory.
Therefore the task work directory should be taken using the attribute task.workDir e.g.
task.workDir.resolve('test.txt').text = "hello $world"
https://github.com/nextflow-io/nextflow/issues/2628#issuecomment-1034189393