1
$\begingroup$

I use Mathematica 11 and create a project containing two files: a package file named MyPackage.m and the other named run.m. The package file contains just normal functions not in special Mathematica package structure (see here), and the other contains code to get MyPackage.m and use the functions.

(* Package.m *)
myFun[x_String] := Print[x]
...

(* run.m *)
<<"Package.m"
myFun["Hello,World"]

I put these two files into one directory and ensure that the $path contains the directory path. But, when I run wolframscript -file ./run.m -print all, it complains $Failed. The question is: how to import another file when using wolframscript? It seems cannot find the destination file even they are in the same directory.

I use Mathematica 11 and run wolframscript in Ubuntu server where I have installed the latest Free CDF Player.


After installing the whole Mathematica at my Ubuntu server, wolframscript run as expected. Maybe the free CDF Player cannot give the full function.

$\endgroup$

closed as off-topic by Alexey Popkov, m_goldberg, Edmund, Young, Mr.Wizard Sep 22 '17 at 5:04

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Alexey Popkov, m_goldberg, Edmund, Young, Mr.Wizard
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ What happens if you replace the contents of run.m with something like Print[Directory[]]; Print[ FindFile[ "Package.m" ] ];Exit[]? $\endgroup$ – Jason B. Sep 13 '17 at 0:44
  • $\begingroup$ Does your .wl or .wls file have the Unix required "shebang" line at the top as specified in the Wolfram Language Scripts tutorial? Did you start with File | New | Package (.wl) or File | New | Script(.wls)? These add a "shebang" line for Unix to the file. Details can also be found in the help on how to construct a more specific "shebang" line. See WolframScript help. $\endgroup$ – Edmund Sep 13 '17 at 1:07
  • 1
    $\begingroup$ Also, I am not certain that wolframscript will run using the Free CDF Player. For one thing the free CDF player cannot load packages so I doubt that even if you could run a .wl or .wls file on it that you would be able to load packages. I think you would need to use the -local or -cloud command line options to point wolframscript to a fully licensed kernel. $\endgroup$ – Edmund Sep 13 '17 at 1:18
  • $\begingroup$ @JasonB. Print[Directory[]] and Print[FindFile["Package.m"]] show correctly. It can find the file "Package.m". $\endgroup$ – hliu Sep 13 '17 at 1:52
  • 1
    $\begingroup$ @b3m2a1Sorry for my poor English..The Mathematica is not installed in my Ubuntu server, only the free CDF Player installed. I found wolframscript was installed at the same time after installing CDF Player, so I decide to use wolframscript to run the script. $\endgroup$ – hliu Sep 13 '17 at 6:00
3
$\begingroup$

Only the full version of Mathematica can evaluate arbitrary code. You have the free CDF player. The CDF player can only open CDF files previously prepared and digitally signed with a full version of Mathematica. It does not allow writing and running new (i.e. unsigned) code.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.