The following function allows me to remotely execute Wolfram code on another machine that has wolframscript installed:
Attributes[remoteExecute] = {HoldAllComplete};
remoteExecute[(* remote_, *) expr_] :=
Module[{compressed, ubuntuBox = RemoteConnect["192.162.0.2", "username", "password"]},
compressed = ExportString[ToString[Hold[expr], InputForm], "Base64"];
ToExpression[
RemoteRunProcess[ubuntuBox,
"wolframscript -format InputForm -code 'ReleaseHold[ImportString[\
\"" <> compressed <> "\",\"Base64\"]]'", "StandardOutput"]]]
For example:
(* Return True: *)
FileExistsQ["~/only_on_my_remote_machine"] // remoteExecute
Problem: This function doesn't work on every function, however, and it is mysterious why:
How to fix?
String
that means the encoding didn't quite go right. By the way this would be easier to write asCompress[Unevaluated[expr]
and then you would execute by callingUncompress[compressed]
. I think you might be happier with that. $\endgroup$ExportString
and don't useImportString
orReleaseHold
. Just do something likeRemoteRunProcess[ubuntuBox, TemplateApply["wolframscript -format InputForm -code 'Uncompress[\"`\`\"]'", Compress[Unevaluated[expr]]]
$\endgroup$Uncompress::corrupt: Compressed data "
ïÂÂ" is corrupt and does \ not represent an expression.` $\endgroup$