help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling an octave function from a BAT file in windows


From: Lars Johansson
Subject: Re: Calling an octave function from a BAT file in windows
Date: Thu, 15 Dec 2016 16:20:52 +0100
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:45.0) Gecko/20100101 Thunderbird/45.5.1

Thanks Kire,

I will give your approach another try (I might have made some mistake before).

/Lars

On 12/15/2016 4:07 PM, Kire Pudsje wrote:
If you really insist on using a function:

myapp.bat
bin\octave-cli -qf myapp.m %*

myapp.m:
[a,b]=myfunction(argv(){:})

You could also remove the intermediate myapp.m.

2016-12-15 12:59 GMT+01:00 Lars Johansson <address@hidden>:
Hi Kire,

Thanks for the hints. This is now my current working solution to handle a very general argument list (arguments separated by spaces). My solution is not beautiful, but for me reasonable ;-). More ideas anyone??

/Lars

¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

From command line or script file (example):

myapp -flag1 data1 -flag2 optionA inputfile outputfile


The solution
---------------------------------------
A BAT file 'myapp.bat' to pass arguments to octave via a temporary file.

@echo off
echo %* > argin.txt
octave-cli -q --eval myapp
del argin.txt

---------------------------------------
An Octave wrapper script 'myapp.m' to read the list of arguments and send it as a 'varargin' list to 'myfunction'

fid=fopen('argin.txt','r');
line = fgetl(fid);
fclose(fid);
argin=strread(line,'%s');
[a,b]=myfunction(argin)

-----------------------------------------
My function 'myfunction' in 'myfunction.m'

function [out1,out2]=myfunction(varargin);
out1='foo';
out2='bar';
% process varargin for whatever purpose







On 12/14/2016 6:35 PM, Kire Pudsje wrote:
echo 1+1 | path\to\bin\octave-cli
ans =  2

or

make a script eg. testfile.m containing:

argv

argv contains the normal input variables, like in C. No argc, but this is just numel(argv).
And run this with
path\to\bin\octave-cli -qf testfile.m arg1 arg2 arg3

ans =
{
  [1,1] = arg1
  [2,1] = arg2
  [3,1] = arg3
}



2016-12-14 10:33 GMT+01:00 Lars Johansson <address@hidden>:
Hi ,

This issue has been up for discussion before, but a quick search did not result in very clear directions?!

Many years ago I used Matlab compiler (on Windows)  to compile a function '[a,b]=myfunction(varargin)'. The result was here an executable 'myfunction.exe' that I called from the command line (or any batch procedure) like

>> myfunction arg1 arg2 arg3

a=

data1
data2
data3
....

b=

data4
data5
data6
....

I am now trying to come up with a BAT file 'myfunction.bat' to do more or less the same thing. Any input would be very much appreciated (here the output is less important than the passing of arguments).

Best regards,

/Lars



_______________________________________________
Help-octave mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-octave

No virus found in this message.
Checked by AVG - www.avg.com
Version: 2016.0.7924 / Virus Database: 4739/13591 - Release Date: 12/14/16



No virus found in this message.
Checked by AVG - www.avg.com
Version: 2016.0.7924 / Virus Database: 4739/13595 - Release Date: 12/15/16



reply via email to

[Prev in Thread] Current Thread [Next in Thread]