Tag Info

Hot answers tagged

46

2014-04-12 NOTICE: MATLAB R2014a contains a bug that breaks MATLink on OS X and Linux (Windows is fine). If you use MATLink on OS X or Linux, please consider keeping MATLAB R2013b until R2014b comes out. Due to the nature of the problem there is no quick workaround that we could apply in MATLink. For full compatibility with Mathematica 10, please upgrade ...


21

On Windows 7 using ReadList instead of Run suppresses the window: Table[Pause[1/2]; ReadList["!dir", String], {3}]; This use of "!command" in place of a file is at least partially documented under OpenRead: On systems that support pipes,OpenRead["!command"] runs the external program specified by command, and opens a pipe to get input from it. As ...


20

Get all the files here: http://JeremyThompson.net/Rocks/Mathematica/MmaWord.zip .Net Mathematica Word Library You will need to use a Microsoft library to open word documents. In a language such as .Net it is very easy; just open Visual Studio, reference the Microsoft.Office.Interop.Word .Net DLL (for Words) and the C:\Program Files\Open XML ...


15

You can call an external (shell) command cmd without showing a command window by using the pipe syntax "!"<>cmd. This can be used in place of a filename with any Mathematica function that opens a file for reading. For example: Import["!dir", "Text"] Read["!dir"] (opens stream, must be closed) OpenRead["!dir"], followed by Read, ReadList etc to grab ...


14

You will find a complete, step by step description of how to write such a program here. Here's a small test program that adds 42 and 137, written by following the tutorial closely: /* mlcall.c */ #include <mathlink.h> #include <stdio.h> int main(int argc, char *argv[]) { MLENV env; MLINK link; int errno; int packet; env = ...


11

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


10

Here I show the basic way to call MATLAB using NETLink under Windows via the MATLAB COM interface. This answer is Community Wiki, feel free to extend it to others platforms and/or improve it! In[1]:= Needs["NETLink`"] matlab = CreateCOMObject["matlab.application"] Out[2]= «NETObject[COMInterface[MLApp.DIMLApp]]» Now one can invoke MATLAB functions: ...


9

I would say JLink is one of the fastest ways to do this. Just use the Runtime to start a process executing your command and collect the exit code too: << JLink` RunThroughWithExitCode[cmd_String] := JavaBlock[Module[{ireader, istream, runtime, process, reader}, LoadJavaClass["java.lang.Runtime"]; runtime = Runtime`getRuntime[]; process = ...


9

Using a slightly modified version of vngx-jsch (source included), an open-source implementation of jsch, and JLink and a small but efficient Mathematica package this is now easily possible. All code can be browsed here, and most simply be installed by executing this twitterable line: (tested on Windows, Linux and Mac, but not on the Raspberry Pi). It should ...


8

The problem has nothing to do with OpenWrite. You never Close the stream you open in your call to Read. Read, unlike ReadList, does not automatically close a stream (file, pipe, etc.) that's given as its first argument string. (That's because the purpose of Read is to be able to read from the same source in pieces, unlike ReadList which does it all at ...


8

The number 2045 is suspicious. Add three to it to include stdin, stdout, and stderr, and you get 2048, which I suspect is total number of file descriptors available to you. I conclude your problem is caused by eating up all the available file descriptors. This is usually caused by doing too many file opens without doing any file closings to return some file ...


8

The command Run will do exactly that. For example, try Run["touch ~/Desktop/blankfile"] If you want to read the results back in, there are a few options, and the choice between them depends on exactly what you want to do. The RunThrough command lets you read the output of a command-line back as a Mathematica expression. For example, try ...


8

Under most operating systems you can use the 2>&1 handle redirection operator(1),(2): Import["!foo 2>&1", "Text"] "'foo' is not recognized as an internal or external command, operable program or batch file."


7

The problem is that the stdin stream for each process is being left open and needs to be closed. To demonstrate the issue, we create a single process: $process = StartProcess[$SystemShell]; WriteLine[$process, "echo example line"]; KillProcess[$process]; The call to WriteLine implicitly creates a stream object. Even though the process has been killed, ...


7

On Windows this works: Run["taskkill /im chrome.exe /f"] Run["taskkill /im WolframPlayerPro.exe /f"]


7

There are many ways to do this on a Mac. For example to open Safari: << "!open -a Safari" To open Safari to a particular file or page: << "!open -a Safari http://mathematica.stackexchange.com/questions/69247/how-to-close-external-app-from-mathematica" Now to close Safari: << "!osascript -e 'tell application \"Safari\" to quit'"


7

Since the CellEvaluationFunction is supposed to accept two arguments, the second being the format type, I recommend defining: GFortran[inp_, _] := . . . and then using it directly: CellEvaluationFunction -> GFortran


7

I'll leave this up on GitHub, but I won't maintain the port. I recommend using MATLink instead. There's a package on the Wolfram Library Archive called mEngine that allows calling MATLAB from Mathematica. What it can do is: execute arbitrary MATLAB commands and retrieve their output as a string transfer array variables between Mathematica and MATLAB ...


6

Table[Pause[1/2]; Import["!dir","Text"];, {3}]; Import can also be used to pipe command line output straight into Mathematica. <<"!dir" Also works.


6

For those who will encounter the same problem as mine (and OP's), I added this answer. Mathematica now(since 10.0.0) has a new built-in function called RunProcess which does exactly what OP asked (including the standard error).


5

We had a bug like this on v. 10: it specifically stopped running new processes after you created 100 of them. This was fixed in version 10.0.1. I recommend testing it there, as version 10.0.1 has a number of improvements with respect to StartProcess. I can't test your example in MacOS right now, so please let me know if this isn't working on v. 10.0.1. ...


5

You can ask MMA to run the traditional ps,grep,kill,killall "unix" shell commands (using for example the RunProcess and Runcommands). The following is more a "Unix" post than a Mathematica one, but ... : For Unix, OS X sytems To "check if some application is opened" :ps and grep For example to see if the Chrome browser is running : myExternalCommand = ...


4

I solved the problem! The solution is quite simple. It is not allowed to distribute the definition of an indirect function to the sub-kernels. Thus, if we do not use ceteris paribus In[17]:= (* DistributeDefinitions[callVert] *) then setting the option DistributedContexts :> None by In[18]:= Map[SetOptions[#,DistributedContexts :> None]&, ...


3

Update -- finally got version 10 StartProcess version: the fortran: program ptest real*8 x do while(.true.) read(*,*)x write(*,*)x**2*cos(x)+1.d0 enddo end this is a simple endless loop, reading from stdin and writing to stdout. now in mathemaitca: pr = StartProcess["ptest"]; f[x_?NumericQ] := (Write[pr, FortranForm[x]]; ...


3

I actually found 3 ways to execute your command with RunProcess (on Unix like systems) : Let's write your command as a string : mycommand = "mdfind -onlyin /some/folder my_string"; but it could be any other command like : mycommand = "ls -la"; Then these 3 inputs are equivalent : RunProcess[StringSplit@mycommand] RunProcess[{$SystemShell, "-c", ...


3

As Mr.Wizard pointed out, you can do this with ParallelSubmit. But you need a little more, and that's the (not so) tricky part as it is not very well documented. I think something like the following should work for you: Needs["Parallel`Developer`"] f[x_] := (Pause[x]; x) LaunchKernels[1] DistributeDefinitions[f] eid = ParallelSubmit[f@5] QueueRun[] Now ...


2

I would do the following. file = OpenWrite[FileNameJoin[{$TemporaryDirectory, "testfile.bat"}]] WriteString[file, "call path"] And then use SystemOpen to call the file.


2

I faced the same problem but I was told here that it was impossible. So, looking for other alternatives I've found it! It's called CoolProp. Given the source files and a Mathematica link file, you need to build a Mathematica-compatible CoolProp.dll yourself. Get them from GitHub Now, I can use it with ease.


2

I googled ".net change working directory", and this link to Microsoft's .NET docs was the first hit: http://msdn.microsoft.com/en-us/library/system.io.directory.setcurrentdirectory(v=vs.110).aspx. It would suggest the following: LoadNETType["System.IO.Directory"] Directory`SetCurrentDirectory["c:\\foo"] To find out the current working directory: ...


1

To call an external command with input parameters like *argv[] in C (I don't know how is it called in Fortran) you can use this Mathematica routine: RunProcess[{$SystemShell, "-c", ExecutableFileName <> " " <> arg1 <> " " <> arg2 <> " " <> arg3}, "StandardOutput"] This will also give back output as a result of the ...



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