Export file to serve while evaluating Wolframscript through command line

Viewed 38

I am trying to use a server to do a set of computations for me, and then export the results as a csv to the server to then be transferred to my own computer. I am having trouble exporting files by remotely running a script. I have a .nb file

a = 1;Export[Directory[] <> "/a.csv", a]

Then I transfer the file to the server and with wolframescript run the script:

$ wolframescript -script /location/filename.nb

I expect a file called a.csv to appear in the directory the .nb file is saved in yet it doesn't. I have tried -run and -file and none of them work either. I have also tried a .wl file and it also doesn't work. What am I doing wrong?

1 Answers

As far as I can tell, when using scripts, file operations are more primitive. Functions OpenWrite OpenAppend Write WriteString and Close are key. Options CharacterEncoding FormatType and PageWidth can help with string data / text files. Your example works on the Desktop with:

a = 1; pipeStream=OpenWrite["a.csv",FormatType->OutputForm]; Write[pipeStream,a]; Close[pipeStream]

Save as Wolframscript from Mathematica "name.wls". On Linux, you need to make the file executable see Wolfram Tutorial.

Then at your respective prompt > $ etc Wolframscript -file name.wls
should run the script file and create a CSV file with the value "1".

This answer reminds that code generated in Mathematica intended for scripting requires Cells to be Initialization cells

Related