# Tag Info

25

If you want readline-like behavior you can of course use a readline wrapper. This works on all operating systems. On Ubuntu Linux (and other distributions I'm sure too) it can be installed easily through the package management. On Max OSX this can be installed using for instance MacPorts and I'm sure, there is an easy option on Windows too. Anyway, on all ...

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 ... 18 If you're on Windows: which command line interface are you talking about? The "math.exe" program is a console mode (i.e. "DOS prompt") interface to the Mathematica kernel. If you use that, you have access to the standard Windows console command-line editing; it is automatically provided by the OS to all console mode programs. You can use the arrow keys to ... 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 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 ...

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 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 ... 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. ... 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 Import["!echo ls -la$HOME", "Text"]

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

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 ...

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

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[...

8

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

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

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 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 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 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

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

Unfortunately, I don't think there is. The association between characters and symbol names is burned into the kernel (in the form of a "yacc" grammar), with complete information about associativity, precedence, and tokenization. Consider something as simple as your dot example. Presumably you want 2.3 to be the real number 2.3, not myDot[2,3]. How would ...

6

I suspect you have to write a script (in Unix/Linux/OSX style) that uses wolframscript as the shell in order to be able to process arbitrary flags from the command line. Consider following script file which peels flag name-value pairs from arguments: #!/usr/bin/env wolframscript -fun (flag1 = flag2 = Missing; FixedPoint[Replace[ {{"-flag1", val_, ...

5

Mathematica does not use readline on Linux so it's simply not possible to do this. You might Google for readline based command line interfaces to Mathematica. That said, I strongly recommend not to use the command line interface unless you simply have no means of using the front end (e.g. working on a remote server through a slow network that makes X ...

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