22

The Run command returns the exit code of the program being run. In your case, the program is "!ls" which probably doesn't exist on your system (If you try sh -c '!ls -la $HOME' you'll also get an error). Why it returns 32512 instead of 127 (which is the return value I get by the shell) I don't know; however I notice that $32512 =127\cdot 256$, so I guess ...


17

When you use the "Base64" you are encoding a particular file format. For Export calls the file format is inferred from the file name given, like Export["file.ext.b64", expr] uses the ext format. When used with ExportString, the format is chosen automatically. You can see here that the automatically chosen format is "String": ExportString["foobar中文", {"...


15

It is not a good idea to try to run a notebook in command line mode. Whether or not it is possible, it is just not a good idea because notebooks can only be handled by the Front End, which is not a command line tool. If you go this route anyway, expect difficulties. The usual way is to extract the code you want to run into a plain text .m file and run ...


14

The -script mode is an interface to the wolfram.exe's -script mode, which is a command-line version of Get. It essentially rewrites the command line, launches a kernel using the equivalent command, and then exits. It can only ever be used with a local kernel, and $ScriptInputString will always be None. In -file mode, wolframscript.exe launches a slave ...


13

(Reposting my comment as an answer) The reason this is happening is that the Mathematica launcher script sets LD_LIBRARY_PATH so that libraries included in the layout will be found and used, and that setting is inherited by any external process started from the kernel. But, sometimes it may happen that the external executable is linked against a conflicting ...


12

I'm not sure on which operating system you are and whether this makes a difference, but your 4 choice don't do the same. math -run file.m edit: When you change this command to math -run < file.m then it does the same as the next (wrong) alternative. Doesn't do anything with the content of file.m at all, because the -run option expects a command like ...


12

For example: RunProcess[{"bash", "-c", "ls -ltr | grep wolf "}, "StandardOutput", ProcessDirectory -> $InstallationDirectory] (* "-rwxr-x---+ 1 Administrators None 551360 Apr 8 09:51 \ wolfram.exe -rwxr-x---+ 1 Administrators None 2390464 Apr 8 09:52 \ wolframscript.exe *)


10

As I said in my comments, it is hard to implement this correctly if you aim for some advanced Dynamic features that work in the command line. However, you can surely use the carriage-return trick on the command line. The only obstacle here is that Print puts everything on a new line. However, if you write directly to stdout, you don't have this problem. ...


9

Update a very simple solution to the OP has been given in this very duplicate post: all the outputs (in particular graphics) are then correctly inserted in the evaluated notebook without the need to insert/modify the original notebook with special commands. also, as asked in the comments, I added a way to monitor in real time the different kind of outputs ...


9

this works for me under linux: SetDirectory[StringDrop[RunProcess["pwd","StandardOutput"],-1]] ( StringDrop drops a trailing "\n" ) Note the directory returned is the same as returned by Directory[] (even if you change it with SetDirectory ), which tells us RunProcess runs in an environment set up by mathematica. Edit This: SetDirectory[StringDrop[...


9

Might be relevant, but this is something I use that uses StartProcess and ProcessConnection. xShow[expr_] := Module[{pr = StartProcess[{"display", "png:fd:0"}]}, WriteLine[ProcessConnection[pr, "StandardInput"], ExportString[expr, "PNG"]]; ] then Plot3D[Sinh[x]Sinc[y],{x,0,Pi},{y,0,Pi}]//xShow results in: This pipes the output to the program ...


8

Import["!`echo ls -la $HOME`", "Text"]


8

Try turning off the "terminal input" system, based on GNU Readline, that was added to math.exe in version 9. Windows has its own terminal input system that works just fine. You can disable the new "terminal input" by running math.exe with the option -rawterm. You can also disable the new "terminal input" permanently by going to the subdirectories Program ...


8

This is a documentation bug that has been fixed recently. The following properly escaped for running in a shell version of the example should work on OS X, commandstring = First[$CommandLine] <> " -noprompt -run \"Put[Factorial[20], FileNameJoin[{\$TemporaryDirectory, \\\"temp1\\\"}] ]; Quit[]\"" Run[commandstring] (* 0 *) FilePrint[...


8

To replicate the Ctrl+A Enter execution behaviour automatically you can run Solve.nb from a package file, say runSolve.m, containing the code below. While Wolfram Language Scripts are straightforward, this method has the advantage that output can be saved in the notebook as if it was being run manually. To run a notebook and monitor evaluation ...


8

Many URL* functions overlap with functionality so there there are many ways. Here is an example which returns a list of rules: URLExecute @ HTTPRequest[ "https://www.googleapis.com/urlshortener/v1/url" , <| "Method" -> "POST" , "Headers" -> {"Content-Type" -> "application/json"} , "Query" -> {"key" -> key} , "Body" -&...


8

I believe the easiest way is to just edit the mathpass file to contain a line that has !server, where server is the name of your network license server. tutorial/ConfigurationFiles should help you determine where the mathpass file is for your platform. (If it doesn't exist, just create it.)


8

Here's a version of the script that works: #!/usr/bin/env wolframscript -print All -run \'Needs[\"ComputerArithmetic`\"]\' Ulp[1000.] This is a limitation of -print All that we probably should either document or find a fix for, though the latter is rather challenging. When executing a script normally or using -print, wolframscript can essentially tell ...


7

"Run" does not return the output of the command. On windows I can do ReadList["!dir", String] and it returns the expected output. I am pretty sure that ReadList["!ls -la", String] will work. I am not too sure about the environmental variable $HOME, buy you can give it a try. For more information see http://reference.wolfram.com/language/tutorial/...


7

The old way, i.e., "C:\Program Files\Wolfram Research\Mathematica\10.1\math.exe" < foo.m > foo.out seems to just work still: This was the way to go back in the early 90's, no so-called FrontEnd on Windows DOS . This also worked quite fine for calculations, even (Postscript) graphics. Of course in Unix you could write nice scripts and run them on ...


7

A better way to check if any scheduled tasks are active is Or @@ ScheduledTaskActiveQ /@ ScheduledTasks[] The reason why this is better is that it uses an API, thus it is more likely to be robust against future changes in the structure of ScheduledTaskObject. In the Raspberry Pi version current as of 2014-06-18, ScheduledTaskObject includes extra options ...


7

I found a way to check for running scheduled tasks, but I am not sure, if the blocking behaviour of Pause is the best thing to do. RunScheduledTask[Print["Bazinga!"], {5, 10}] (* a lot of code *) (* till the end of script *) While[ Or@@ScheduledTasks[][[All, 5]], Print[DateString[]]; Pause[1]] Output: C:\Software\Dev>math -script test.m "Wed 18 Jun ...


7

No. In fact, even $PreRead is ignored when reading .m files. What you can do is define a myGet as myGet[file_] := Module[{str}, str = Import[file,"Text"]; str = myTextReplacemeansts[str]; ToExpression[str]; ] to make your own substitutions.


7

RunProcess does not run shell commands (things you might type into your terminal). It runs processes, as the name suggests. If you want to run shell commands, then you have these options: Run (it does not give you the output) Import["!yourcommand", "String"] or similar (to get the output) Run your shell with RunProcess/StartProcess and pass the commands to ...


7

If you prepend bash -c to your RunProcess command, you can pass ls -ltr | tail -1 as a single argument (at least with v12 on Windows 7 with cygwin or Windows 10 with the subsystem for linux). RunProcess[{"bash", "-c", "ls -ltr | tail -1"}, "StandardOutput"]


6

Clusters can be significantly different from each other, so I strongly recommend you talk to someone who uses the same system and ask them for help with the details. However, there is one thing that is clearly incorrect in your job script: To run a script with Mathematica, you need to start the kernel (command line program), not the front end (graphical ...


6

This question is more complicated that you might expect. Things you can check: Given how you want to use this, the simplest thing may be to just check if NotebookDirectory[] is different from $Failed. The documentation would suggest $Notebooks, but be careful: this is True even if running in command line mode but connecting to a front end anyway, e.g. ...


6

Here is a crude progress bar demo script that has been tested in a Gnome terminal under Linux and a Powershell command prompt under Windows 10. Don't expect much because it's only a loop with a print statement: progbar[width_, title_] := Function[{ndx}, Print[ " " <> title<>"\n [" <> StringJoin@ConstantArray["*", ndx] &...


6

This is an execution mode I don't think we encountered in internal testing for the new wolframscript, the thought being that such processing would occur early in the script, an any needed values would be passed in as arguments. I'm not 100% sure what's happening here--I should think that it would fall back to legacy mode and support this. @dsingh has ...


6

To make the path permanently available to Mathematica (frontend) and all other applications, first find out the location of your desired python3 executable (e.g. from which python3 in the Terminal), and then add this to the path variable that is set for all applications when the user logs in. Let's say the executable is in /usr/local/bin as @b3m2a1 mentioned ...


Only top voted, non community-wiki answers of a minimum length are eligible