Question

Is there a possibility to use Octave headless.

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

Was it helpful?

Solution

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.

OTHER TIPS

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top