Group Abstract Group Abstract

Message Boards Message Boards

interface to external program / command line and optimisation [beginner]

Posted 10 years ago
POSTED BY: geotrupes a
6 Replies
Posted 10 years ago

The ToExpression solves the issue and all works!! I am very new to Mathematica an trying to run without knowing how to walk :-) If there is a better way and you have some idea please shoot! Thank you, G>

POSTED BY: geotrupes a
Posted 10 years ago
POSTED BY: geotrupes a
Posted 10 years ago

You think you are seeing this behaving as you expect

In[1]:= f[x_?NumericQ] := RunProcess[{"echo", ToString[InputForm[x^2, NumberMarks->False]]},"StandardOutput"];
   f[3]

but if you then do this

Print[FullForm[%]]

I believe you will understand that your function is returning a string, not a numeric value, and trying to "minimize a string" isn't going to work.

If you are running Windows then

f[x_?NumericQ] := ToExpression[StringDrop[RunProcess[{"echo", ToString[InputForm[x^2, NumberMarks->False]]}, "StandardOutput"], -2]];
Print[FullForm[f[3]]]

might be closer to what you want. And if you aren't running Windows then the StringDrop may need to be adjusted to match your local conventions.

I think there should be a much better way of doing what you are trying to do.

POSTED BY: Bill Simpson
Posted 10 years ago

Thank you Bill, tried and it works

f[x_?NumericQ] := CompoundExpression[
  SetDirectory["~/Desktop/test"];
  Print[N[x]]; 
  Export["in.data", N[x], "Text"];
  Run["~/Desktop/test/run.sh"]; 
  result = N[ToExpression[Import["out.data"]]] ;
  Run["rm *.data"];
  Print[result]

There are few issues to resolve but this is great.

THANK YOU! G.

PS do you happen to know if this is running in a multicore fashion?

POSTED BY: geotrupes a
Posted 10 years ago
POSTED BY: geotrupes a
Posted 10 years ago

Perhaps this

POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard