4
$\begingroup$

I need to run an external program to process some files. I have added the location of the program to my .bash_profile (I use a mac) and I have verified that executing the program in Terminal works.

However, whenever I execute Run["program"] Mathematica returns 32512. I suppose this is some error code but I can't find what it means.

Whatever idea you have will help me.

$\endgroup$
5
  • $\begingroup$ Try the answers in this question how-to-trigger-unix-command-line-command-from-mathematica-notebook Same error code there. This code looks like the exit code from the program you ran. $\endgroup$
    – Nasser
    Aug 28, 2016 at 6:10
  • $\begingroup$ I think that code is either coming from the OS or Mathematica, since I get the same output no matter what I Run. $\endgroup$
    – amrods
    Aug 28, 2016 at 6:48
  • $\begingroup$ try running a system command, like "ls" or "dir" and see if you get same code. It works for me when I do Run["DIR"] no problem. $\endgroup$
    – Nasser
    Aug 28, 2016 at 8:02
  • $\begingroup$ you were right, "ls" returns 0, could it be that Mathematica is not finding the program I'm trying to run? $\endgroup$
    – amrods
    Aug 28, 2016 at 8:05
  • $\begingroup$ RunProcess will return an Association with more status info about the program you tried to execute. $\endgroup$
    – masterxilo
    Aug 31, 2016 at 1:06

1 Answer 1

4
$\begingroup$

Your problem is likely to be that the program you are trying to run is not on the path that Mathematica is using. To see this you can use:

file = CreateTemporary[];
Run[StringJoin["echo $PATH >", file]];
FilePrint[file]

I get the following

/usr/local/Wolfram/Mathematica/11.0/Executables:/usr/local/Wolfram/Mathematica/11.0/SystemFiles/Graphics/Binaries/Linux-x86-64:/usr/local/Wolfram/Mathematica/11.0/Executables:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/bin/X11
$\endgroup$
4
  • $\begingroup$ right, I get only /usr/bin:/bin:/usr/sbin:/sbin, even when I edit my .bash_profile to add the path of the program I want to run... $\endgroup$
    – amrods
    Aug 28, 2016 at 19:48
  • 1
    $\begingroup$ Can you specify the full path to the program in the call e.g. Run["/path/to/program"]? Or use Run["bash -c Program"]? $\endgroup$
    – mikado
    Aug 28, 2016 at 20:09
  • $\begingroup$ Run with the full path works. What does bash -c program do? $\endgroup$
    – amrods
    Aug 28, 2016 at 20:30
  • 1
    $\begingroup$ It uses bash to run the program. If you have set up the path correctly for bash, it should then be able to launch the program. $\endgroup$
    – mikado
    Aug 28, 2016 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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