Files

After we have learned how to use Cuneiform and other languages with Cuneiform, let's dive into something a little more complex - using Cuneiform with files. Right now, our workflows are pretty limited. We can use input strings or integers and receive output strings. Well, what if your input is not a simple value, but a whole file?
And what if you want to save the ouput into a file? Yes, of course this is possible (otherwise this tutorial would be useless, right?). Per default, Cuneiform assumes that the input parameters are strings. For the following, assume we have a file called "echo.txt" with the content:

I am the content of the echo file.
We run Cuneiform inside the folder where the echo.txt is located. Try the following:

deftask scan( out : inp ) in bash *{
	out=$(<$inp)
}*

file = 'echo.txt';
scan(inp: file);

If you've done everything right, you should have been rewarded with an error message, that looks somewhat like this:

Error channel: "./cfscript: line 35: echo.txt: No such file or directory Task invocation returned non-zero exit value. "
Why did this happen? Because we did not tell Cuneiform that this time we don't want to handle a variable of type string with the value "echo.txt", but a file. To receive the intended output, all we need to do is expand the task definition by adding a simple "(File)" keyword after the input parameter "inp". The resulting workflow looks like this:

deftask scan( out : inp(File) ) in bash *{
	out=$(<$inp)
}*

file = 'echo.txt';
scan(inp: file);

Upon execution you will receive the content of the file as output variable. See, pretty easy, right? The same applies to the output, if you want the output to be a file, simply add "(File)".
This is useful, if the output will be used as input in another task:

deftask scan( out : inp(File) ) in bash *{
	out=$(<$inp)
}*

deftask copy( out(File) : inp(File) ) in bash *{
	cat $inp > $out
}*

file = 'echo.txt';
cp = copy(inp: file);
scan(inp: cp);

Of course you can handle these files just the way you handled traditional variables as seen in the previous tutorials. Create lists, feel free to write a few experimental workflows.

That is pretty much all you need to know about files as input and output parameters. Except for... where can you find these output files?
On Unix-based systems, if you use the default settings when running Cuneiform and did not temper with the "-l" or "-localcache" option, you will find a folder named ".cuneiform" at '~/.cuneiform'. Depending on how often you used Cuneiform before, you might find a fairly large amount of subfolders here, each named with 10 digits, for example "3391716791". Each folder corresponds to one task that you executed. That means if you issued a job with two task definitions (assuming you used these once in the workflow), there will be two folders. Each folder is a combination of "task definition and input", so using the same task with two different inputs will generate two different folders. You can find the outputs of each task in the specific folder, or, way easier - use the "repo" folder. If you've given your output files recognizable names, like in this example:

deftask scan( out(File) : inp(File) ) in bash *{
	out="iamanoutputfile";
    value=$(<$inp)
    echo value>$out;
}*

file = 'echo.txt';
scan(inp: file);

The output is
INFO  Query 911747ce-8b0b-421b-879d-1b5623c0d412 finished: '5197183835_1_iamanoutputfile'
And like magic, inside the repo folder is a file link to the file 5197183835_1_iamanoutputfile.