I want to run a short code like that in the linux command line

(*Set the work directory*)    
(*Import the data source*)
testdata = Import["test.csv"] // Flatten;
plot = ListPlot[testdata];
Export["myplot.png", plot]

the test.csv is a csv file which is in the same directory with the script. the file just contain some numbers as follow.


now I want to import the file, and export the list plot named as myplot.png. The code runs good in the Mathematica front-end Notebook on the windows platform . But I need to run this code in remote commands line. So I save this code from test.nb to test.m, and run the code as follow on the linux platform

MathematicaScript -script test.m


MathKernel -noprompt -initfile test.m


math -noprompt -script test.m 

I get nothing.

then I save the .nb file as wolfram language package, and run

wolfram -script test.wl

but I still get noting.

  • 1
    $\begingroup$ Your procedure works ok, but you have to SetDirectory to something else then NotebookDirectory[] (e.g. explicit directory name) because you are not using a notebook. $\endgroup$ – Pinti Jul 3 '17 at 17:11
  • $\begingroup$ @Pinti Thank you. I changed the work directory, and tried the four command line. but I do not get the output file myplot.png $\endgroup$ – Zihu Guo Jul 3 '17 at 23:54
  • $\begingroup$ Try the front end function been a while since I tried this but might work. $\endgroup$ – William Jul 4 '17 at 0:02
  • $\begingroup$ @William Thank you, could you explain in more detail $\endgroup$ – Zihu Guo Jul 4 '17 at 0:12
  • $\begingroup$ @ZihuGuo try evaluating your code in FrontEndExecute[code] or maybe UsingFrontEnd that is all I can recall. $\endgroup$ – William Jul 4 '17 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.