Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using octave headless

Is there a possibility to use Octave headless.

Something like this octave < "5+4" >result.txt

like image 268
Mhh Lecker Avatar asked May 05 '11 19:05

Mhh Lecker


2 Answers

Using

octave --silent --eval 5+4 > result.txt

you'll get

ans =  9

in result.txt. See octave --help for details about command-line arguments.

Yet, there is this infamous ans = that might be remove using sed, e.g.

octave --silent --eval 'x=5+4; y=x+1; disp(y)' | sed -e 's/ans = //' >> result.txt

which add the appropriate result (10) in result.txt.

It should not be too hard to wrap this into a bash script.

like image 51
chl Avatar answered Nov 04 '22 19:11

chl


Well there is always the option of writing a script file which saves the results of your computations to a text file. Then when invoking octave you just do:

octave scriptname.m

for example: testfile.m

Return = 5+4;
save('results.txt','Return')

Then from the command line:

octave -q testfile.m

and you should get the results you want in a file called results.txt and it will immediately terminate after. Is there some reason why this option wont work?

like image 35
dynamphorous Avatar answered Nov 04 '22 21:11

dynamphorous