0
$\begingroup$

I have a question regarding the function "Runprocess" and the architecture of Mathematica(probably).

I would like to admit in advance that my knowledge is not solid enough in Mathematica, therefore, sorry for some unclarity in advance.

The problem is that I use a function Runprocess which is written in the following way

simu[{DD_?NumberQ}] := (1 - 
   Interpreter["Number"][
    StringSplit[
     RunProcess[{"C:\\Program Files (x86)\\SIMPSON\\simpson" , 
       "C:\\Users\\Timur\\Desktop\\nmr\\simpson_code\\redor2d_ty.in", 
       ToString[DD], ToString[0]}, "StandardOutput"]]])
ListLinePlot[(simu[{9000}]), PlotRange -> All]

The main part contains the path of 2 files (one is where the program is stored, another is the file to run). As it can be seen, everything is written on Windows 10 OS. Problem is that my program has a bug in Windows, therefore, I use WSL to run my program.

And now I would like to run the same program from Linux system (or from wsl).

And I get an error


In[137]:= 
simu[{DD_?NumberQ}] := (1 - 
   Interpreter["Number"][
    StringSplit[
     RunProcess[{"/usr/local/bin/simpson" , 
       "C:\\Windows\\System32\\Simpson\\redor2d_ty[4048].in", 
       ToString[DD], ToString[0]}, "StandardOutput"]]])
ListLinePlot[(simu[{9000}]), PlotRange -> All]

During evaluation of In[137]:= RunProcess::pnfd: Program /usr/local/bin/simpson not found.  Check Environment["PATH"].

During evaluation of In[137]:= StringSplit::strse: String or list of strings expected at position 1 in StringSplit[$Failed].

During evaluation of In[137]:= ListLinePlot::lpn: 1. -1. Failure[\[WarningSign] Message:    Enter a valid number.
Tag:    RestrictionFailure

] is not a list of numbers or pairs of numbers.

Out[138]= ListLinePlot[1 - Failure["RestrictionFailure", 
Association[
   "MessageTemplate" :> MessageName[Interpreter, "number"], 
    "MessageParameters" -> Association["Input" -> {
StringSplit[$Failed]}], "Input" -> {
StringSplit[$Failed]}, "Type" -> "Number"]], PlotRange -> All]

I assume the problem is that my path for the Linux program is not detected.

So, the question is whether it is possible to call a function in this way. Or is it necessary to use Mathematica in Linux subsystem? If so, then how?

$\endgroup$
3
  • $\begingroup$ I think the path in LINUX is written with forward slashes. $\endgroup$ Commented May 6, 2021 at 16:52
  • 1
    $\begingroup$ You cannot directly invoke a Linux executable from Windows. You would have to use the wsl utility to run it for you. Check out the docs docs.microsoft.com/en-us/windows/wsl/…. $\endgroup$
    – ihojnicki
    Commented May 7, 2021 at 2:32
  • $\begingroup$ I would like to thank everyone for your comments.I have found a solution. RunProcess[{"cmd", "/c", "wsl", "simpson", "/mnt/c/windows/system32/simpson/redor2d_ty.in"}] $\endgroup$ Commented May 7, 2021 at 16:01

1 Answer 1

2
$\begingroup$
 simu[{DD_?NumberQ}] := (1 - 
   Interpreter["Number"][
    StringSplit[
     RunProcess[{"cmd", "/c", "wsl", "simpson", 
       "/mnt/c/windows/system32/simpson/redor2d_ty.in", ToString[DD], 
       ToString[0]}, "StandardOutput"]]])
ListLinePlot[(simu[{9000}]), PlotRange -> All]
$\endgroup$

Your Answer

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

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