From: Jeff Baker on
Any suggestions for how to continuously pipe data from a dos program?

Approximately once per second the dos program has a data packet. I need to know when it is ready and then receive it. I do not want to place a blocking call using the Matlab dos() command because that will cause the dos executable to load every time and this would be too slow. It is much better to have the dos program active in the background, then somehow have an event fire within Matlab and cause a callback function to run every time it has a packet ready.

Thanks,

Jeff
From: Walter Roberson on
Jeff Baker wrote:
> Any suggestions for how to continuously pipe data from a dos program?
> Approximately once per second the dos program has a data packet. I need
> to know when it is ready and then receive it. I do not want to place a
> blocking call using the Matlab dos() command because that will cause the
> dos executable to load every time and this would be too slow. It is
> much better to have the dos program active in the background, then
> somehow have an event fire within Matlab and cause a callback function
> to run every time it has a packet ready.

There is no Matlab mechanism to open an independently executing process
and communicate with it. I would, however, not be surprised if there is
a Java mechanism that could be invoked inside of Matlab.

If Matlab can run without keyboard input for your purposes, then in
theory you could fire up

dosprogram | matlab -r "YourMFile;quit"

and then within YourMFile, at each point that you want input,

fseek(1, ftell(1), 'bof');

and then fread(1) until you hit end of file. It may seem silly to seek
to the exact same position you are at, but doing so is defined to reset
the end-of-file flag and thus to permit all accumulated new input to be
read.

That's the theory; I haven't tried it in practice in Matlab, and the
experiments that I didn't do were especially not carried out under Windows.
From: Jeff Baker on
Walter Roberson <roberson(a)hushmail.com> wrote in message <bcEQn.76021$HG1.54740(a)newsfe21.iad>...
> Jeff Baker wrote:
> > Any suggestions for how to continuously pipe data from a dos program?
> > Approximately once per second the dos program has a data packet. I need
> > to know when it is ready and then receive it. I do not want to place a
> > blocking call using the Matlab dos() command because that will cause the
> > dos executable to load every time and this would be too slow. It is
> > much better to have the dos program active in the background, then
> > somehow have an event fire within Matlab and cause a callback function
> > to run every time it has a packet ready.
>
> There is no Matlab mechanism to open an independently executing process
> and communicate with it. I would, however, not be surprised if there is
> a Java mechanism that could be invoked inside of Matlab.
>
> If Matlab can run without keyboard input for your purposes, then in
> theory you could fire up
>
> dosprogram | matlab -r "YourMFile;quit"
>
> and then within YourMFile, at each point that you want input,
>
> fseek(1, ftell(1), 'bof');
>
> and then fread(1) until you hit end of file. It may seem silly to seek
> to the exact same position you are at, but doing so is defined to reset
> the end-of-file flag and thus to permit all accumulated new input to be
> read.
>
> That's the theory; I haven't tried it in practice in Matlab, and the
> experiments that I didn't do were especially not carried out under Windows.

Thanks Walter, good straightforward answer. I will try it in windows. I also thought of setting up a ramdisk. I would dump dos output into a file and watch it from matlab.