Message Boards Message Boards

WolframScript: Compute in the cloud, export results locally?

I was playing around with WolframScript last night (Windows 10, standard native command line). I really like it, but I did run into a problem: If I execute code on the cloud servers, exported files end up in my cloud directory. Is there a way to export to a local directory instead? I'm probably missing something very obvious since this was my first attempt with WolframScript.

Here's my example: The script file:

#!wolframscript
Export["testplot.png",Graphics3D[Sphere[]]];
Print[AbsoluteFileName["testplot.png"]];

And here's the behaviour for both a local kernel and a cloud kernel:

enter image description here

(I realize I can get the image to my dropbox with the Services framework, but I'm more concerned about the general case where the local directory could be anywhere on my computer.)

By the way, the following example from the Documentation doesn't work for me; it simply produces a broken image file (Windows problem, maybe?):

wolframscript -code 'Graphics3D[Sphere[ ]]' -format PNG > file.png

Anyway, this example leads me to believe that redirecting output is the preferred method, as opposed to using Export in the script file itself; is that correct? (The output file is saved locally regardless of whether I use the -cloud option.) But even if I get the example to work, what if I need multiple exports from the same script?

POSTED BY: Bianca Eifert
3 Replies

Thank you both for the answers!

The output redirection indeed works fine without the quotes, and more importantly, it also works on a script file:

wolframscript -o -f test.wl -format PNG > file.png

where the last line of the script file is a Print of whatever plot I want. That's pretty cool. Seems like it was really just a Windows issue.

Your CloudEvaluate-and-copy approach also works. However, I had some hope that there'd be a standalone wolframscript installer soon which would allow us to run code on machines that do not have a local WL kernel. (Maybe even with a portable executable that doesn't require admin access, that would be really awesome.) I'm not trying to skimp on the license, but it's just not always possible or practical.

David - that's a valid point about the cloud credentials, especially with the all-purpose Wolfram account (where the same credentials will get you into the user portal and this forum and all the other cloud services as well). Maybe a second dummy account would help, but I have a feeling that that's very much not encouraged... For what it's worth, the stored credentials on my computer look encoded at first glance.

Anyway, wolframscript is still awesome for use with a local kernel, I really apprectiate the addition. I like the frontend as much as the next person, but sometimes scripts are just so much more convenient.

POSTED BY: Bianca Eifert

I don't think there will be any way to send the output from the cloud to your machine. A possible workaround is to run your script locally, but have it call CloudEvaluate. Here's my script that does this, and then copies the file from the cloud to my local machine. Not beautiful, but it works.

#!wolframscript
CloudConnect["chadk@wolfram.com","xxxx"];
CloudEvaluate[Export[CloudObject["testplot.png"],Graphics3D[Sphere[]],"PNG"]];
CopyFile[CloudObject["testplot.png"],"localttestplot.png"];
Print["all done!"];

Or you could have a 2nd script that calls CopyFile the output from your first script. But that seems even worse.

I also can reproduce the Windows issue. For some reason the single quotes don't work in Windows. If you open the png file with a text editor, you'll see an error message: ToExpression::sntx: Invalid syntax in or before "'Graphics3D[Sphere[]]'". It works without the single quotes:

wolframscript -code Graphics3D[Sphere[]] -format PNG > file.png

Note: note space between the brackets.

POSTED BY: Chad Knutson
Posted 8 years ago

I was able to get a correct output using both local and cloud forms on OS X 10.10.5 Mathematica 11.0:

wolframscript -code 'Graphics3D[Sphere[ ]]' -format PNG > file.png
wolframscript -cloud -code 'Graphics3D[Sphere[ ]]' -format PNG > file.png

I am not sure how to pass Wolfram cloud credentials without typing them however, this seems problematic for using wolframscript in many cases....

POSTED BY: David Proffer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract