Redirecting Octave IO

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Redirecting Octave IO

Richard Crozier-2
  Hello,

I would like to use octave as a child process in a C#.NET application.
Basically I'm writing a little gui for octave. I can successfully
connect to octave and redirect stdin, stdout and stderr to streams in
C#. However, I have a problem that Octave does not always seem to send
the prompt to stdout, so I cannot tell if a computation has been completed.

For instance, if I set the octave prompt to be '>>' and I pass octave a
command which results in an output, e.g. 'x = 1\r' where '\r' is the
return character of course. I get back the string '>> x = 1'

However, if I pass in 'x = 1;\r' I get nothing immediately. At the next
input of a command that requires output however, I will then get a
string of prompts in the output stream.

e.g.

sending \r' followed by 'x = 1;r' followed by '\r' followed by 'x = 2\r'
will yield nothing in the ouput stream until after the last command when
I will get something like: '>> >> >> x = 2'

Is there any way to force octave to always send the prompts to the
output, i.e. replicating what happens when it is run in the normal way?

I have tried setting 'more off' and calling fflush(stdout) before and
after sending command strings but nothing seems to work. The biggest
problem is not knowing when octave is finished processing the last command.

Thanks

--
Richard Crozier, Research Associate
Institute for Energy Systems
School of Engineering and Electronics
The University of Edinburgh
Faraday Building, Room 4.124
The King’s Buildings
Edinburgh EH9 3JL

Phone: 0131 651 9023
Fax: 0131 650 6554


The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Redirecting Octave IO

Jordi Gutiérrez Hermoso
On 4 February 2011 10:20, Richard Crozier <[hidden email]> wrote:
> Basically I'm writing a little gui for octave.

Goodness gracious, another one?

> Octave does not always seem to send the prompt to stdout, so I
> cannot tell if a computation has been completed.

Is this related to the pager? Perhaps you should disable all paging.
Look at the page_screen_output function. Perhaps that's what you need
to toggle. You said you did toggle it, hm, perhaps
page_output_immediately is also related, although it shouldn't be.

Regardless, the proper way to do this, which OctaveDE has implemented,
is to hook onto the readline idle hook. There are many other problems
besides the ones you're experiencing if you try to communicate with
pipes like that (or whatever the Windows equivalent to a pipe is), but
the readline method avoids all of these problems, in exchange for the
problem of being a bit harder to code.

HTH,
- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Redirecting Octave IO

Martijn Brouwer-9
In reply to this post by Richard Crozier-2
Hi,
If you insist on doing this, you can try 'expect', which basically
automates typing at the console. I have used it to connect
to a modem using telnet and it works fine.
However, I suggest you only do this for a niche application. There are
GUI's for octave, especially a number of unfinished ones.

Martijn

On Fri, 2011-02-04 at 16:20 +0000, Richard Crozier wrote:

> Hello,
>
> I would like to use octave as a child process in a C#.NET application.
> Basically I'm writing a little gui for octave. I can successfully
> connect to octave and redirect stdin, stdout and stderr to streams in
> C#. However, I have a problem that Octave does not always seem to send
> the prompt to stdout, so I cannot tell if a computation has been completed.
>
> For instance, if I set the octave prompt to be '>>' and I pass octave a
> command which results in an output, e.g. 'x = 1\r' where '\r' is the
> return character of course. I get back the string '>> x = 1'
>
> However, if I pass in 'x = 1;\r' I get nothing immediately. At the next
> input of a command that requires output however, I will then get a
> string of prompts in the output stream.
>
> e.g.
>
> sending \r' followed by 'x = 1;r' followed by '\r' followed by 'x = 2\r'
> will yield nothing in the ouput stream until after the last command when
> I will get something like: '>> >> >> x = 2'
>
> Is there any way to force octave to always send the prompts to the
> output, i.e. replicating what happens when it is run in the normal way?
>
> I have tried setting 'more off' and calling fflush(stdout) before and
> after sending command strings but nothing seems to work. The biggest
> problem is not knowing when octave is finished processing the last command.
>
> Thanks
>


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Redirecting Octave IO

Richard Crozier-2
In reply to this post by Jordi Gutiérrez Hermoso
Quoting Jordi Gutiérrez Hermoso <[hidden email]>:

First of all, thanks for replying.

>> Basically I'm writing a little gui for octave.
>
> Goodness gracious, another one?
>

Yes, one which will actually implement the features I want! Also just  
a little project for myself.

Actually I have sort of discovered the problem. I had been setting the  
output prompt to ">> " via the command PS1('>> '). When I do this, I  
get the described problem. However, if I don't do this octave returns  
a string containing the executeable name and the current directory  
after finishing a command. I'll just look for this text in the input  
from octave in future.

Thanks



--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Redirecting Octave IO

Jordi Gutiérrez Hermoso
2011/2/5 RC Crozier <[hidden email]>:

> Quoting Jordi Gutiérrez Hermoso <[hidden email]>:
>
> First of all, thanks for replying.
>
>>> Basically I'm writing a little gui for octave.
>>
>> Goodness gracious, another one?
>>
>
> Yes, one which will actually implement the features I want! Also just a
> little project for myself.

What features are those? Could you help us fix one of the more popular
GUIs instead? This constant NIH with Octave IDEs/GUIs is really not
helping. You could do a lot more good by working on, say, fixing
QtOctave than starting another half-baked GUI that you'll get bored
with in a few months and abandon. Maybe you'll be different from the
dozens of other people who have decided to start a GUI or IDE for
Octave, but the odds are not in favour of this.

- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Redirecting Octave IO

Richard Crozier-2
Quoting Jordi Gutiérrez Hermoso <[hidden email]>:

> 2011/2/5 RC Crozier <[hidden email]>:
>> Quoting Jordi Gutiérrez Hermoso <[hidden email]>:
>>
>> First of all, thanks for replying.
>>
>>>> Basically I'm writing a little gui for octave.
>>>
>>> Goodness gracious, another one?
>>>
>>
>> Yes, one which will actually implement the features I want! Also just a
>> little project for myself.
>
> What features are those? Could you help us fix one of the more popular
> GUIs instead? This constant NIH with Octave IDEs/GUIs is really not
> helping. You could do a lot more good by working on, say, fixing
> QtOctave than starting another half-baked GUI that you'll get bored
> with in a few months and abandon. Maybe you'll be different from the
> dozens of other people who have decided to start a GUI or IDE for
> Octave, but the odds are not in favour of this.
>
> - Jordi G. H.
>
>

So far I have tried two GUIs, QToctave and XOctave, perhaps there are  
others I am not aware of, such as OctaveDE, which I haven't tried. The  
main problem with both of these is that they do not offer a similar  
experience to the matlab GUI . What I really want is the ability to  
certain things such as:

1. select some text in the command window, press the F9 key and have  
it sent to octave as a command.

2. select some text in an editor window, press the F9 key and have it  
sent to octave as a command.

3. have an editor window (with the above ability) with decent syntax  
highlighting (I plan to implement this with scintillaNET, a .NET  
control that wraps scintilla).

4. The ability to copy and paste text in the command window using C-c  
and C-v, not currently possible in the windows console.

5. The ability to step forward etc. when debugging by pressing one of  
the F keys

Xoctave comes closest to these abilities, but is buggy and implemented  
in Pascal, a language I am not familiar with.

QToctave is ok, but seems focussed on the visual aspect of the  
experience, such as showing the contents of variables and whatnot  
rather than these other things which I regard as the core abilities of  
the matlab GUI, and are what really speed up algorithm development for  
me in my work. I could contribute to qtoctave, but it would require  
learning the existing codebase, and many things I don't know about. By  
implementing my gui as as a .NET windows forms I have the many windows  
forms controls available to me, the extensive documentation of these  
contols, and my existing experience. It won't be cross-platform, but  
you can't have everything. I also need it work in all flavours of  
windows flawlessly. I think I can get the features I want working in a  
buggy fashion in about a week using C#.NET. I already have a few  
working.

Also, this is just for myself, I would be happy to release it for  
others, open source, especially if others would help me, but I just  
want it to do what I want really.


--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Redirecting Octave IO

Laurent Hoeltgen
On Sun, 2011-02-06 at 13:40 +0000, RC Crozier wrote:

> Quoting Jordi Gutiérrez Hermoso <[hidden email]>:
>
> > 2011/2/5 RC Crozier <[hidden email]>:
> >> Quoting Jordi Gutiérrez Hermoso <[hidden email]>:
> >>
> >> First of all, thanks for replying.
> >>
> >>>> Basically I'm writing a little gui for octave.
> >>>
> >>> Goodness gracious, another one?
> >>>
> >>
> >> Yes, one which will actually implement the features I want! Also just a
> >> little project for myself.
> >
> > What features are those? Could you help us fix one of the more popular
> > GUIs instead? This constant NIH with Octave IDEs/GUIs is really not
> > helping. You could do a lot more good by working on, say, fixing
> > QtOctave than starting another half-baked GUI that you'll get bored
> > with in a few months and abandon. Maybe you'll be different from the
> > dozens of other people who have decided to start a GUI or IDE for
> > Octave, but the odds are not in favour of this.
> >
> > - Jordi G. H.
> >
> >
>
> So far I have tried two GUIs, QToctave and XOctave, perhaps there are  
> others I am not aware of, such as OctaveDE, which I haven't tried. The  
> main problem with both of these is that they do not offer a similar  
> experience to the matlab GUI . What I really want is the ability to  
> certain things such as:
>
> 1. select some text in the command window, press the F9 key and have  
> it sent to octave as a command.
>
> 2. select some text in an editor window, press the F9 key and have it  
> sent to octave as a command.
>
> 3. have an editor window (with the above ability) with decent syntax  
> highlighting (I plan to implement this with scintillaNET, a .NET  
> control that wraps scintilla).
>
> 4. The ability to copy and paste text in the command window using C-c  
> and C-v, not currently possible in the windows console.
>
> 5. The ability to step forward etc. when debugging by pressing one of  
> the F keys
>
> Xoctave comes closest to these abilities, but is buggy and implemented  
> in Pascal, a language I am not familiar with.
>
> QToctave is ok, but seems focussed on the visual aspect of the  
> experience, such as showing the contents of variables and whatnot  
> rather than these other things which I regard as the core abilities of  
> the matlab GUI, and are what really speed up algorithm development for  
> me in my work. I could contribute to qtoctave, but it would require  
> learning the existing codebase, and many things I don't know about. By  
> implementing my gui as as a .NET windows forms I have the many windows  
> forms controls available to me, the extensive documentation of these  
> contols, and my existing experience. It won't be cross-platform, but  
> you can't have everything. I also need it work in all flavours of  
> windows flawlessly. I think I can get the features I want working in a  
> buggy fashion in about a week using C#.NET. I already have a few  
> working.
>
> Also, this is just for myself, I would be happy to release it for  
> others, open source, especially if others would help me, but I just  
> want it to do what I want really.
>
Hi,

just my two cents about your requirements. Emacs can probably be
configured to do what you need. My personal favourite so far, is Geany
http://www.geany.org/ Sending a whole m file to octave and getting a
little popup window with the result can be done with F5 and works out of
the box. No configuration needed. Sending specific lines that you have
highlighted can probably be done too. The editor is capable of sending
text to a terminal. So sending it to octave should be possible as well.
If not, the editor can easily be extended with plugins (either written
in C or Lua) Also it uses the scintilla text component, thus the syntax
highlighting is pretty fine. Finally geany works on Windows as well as
Linux. So why not considering extending the capabilities of editors that
already have a solid base instead of writing new ones?

Greetings,
Laurent


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave

signature.asc (501 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Redirecting Octave IO

Jordi Gutiérrez Hermoso
In reply to this post by Richard Crozier-2
2011/2/6 RC Crozier <[hidden email]>:
> 1. select some text in the command window, press the F9 key and have it sent
> to octave as a command.

Okay, QtOctave doesn't do this one.

> 2. select some text in an editor window, press the F9 key and have
> it sent to octave as a command.

Did you even try it? QtOctave implements this.

> 3. have an editor window (with the above ability) with decent syntax
> highlighting (I plan to implement this with scintillaNET, a .NET
> control that wraps scintilla).

QtOctave does have its own editor with its own syntax highlighting,
but perhaps you consider it indecent.

> 4. The ability to copy and paste text in the command window using
> C-c and C-v, not currently possible in the windows console.

QtOctave does this, in its weird way, because it's making the same
mistake you are making and many other attempts at writing a GUI have
made: sending output via a pipe (i.e. redirecting IO), instead of
hooking onto the readline idle loop. OctaveDE is the only one I know
that gets this right.

> 5. The ability to step forward etc. when debugging by pressing one
> of the F keys

This is kind of implemented but not too well in QtOctave. Debugging is
possible but awkward. And I think you're underestimating how difficult
it is to get it working correctly. You won't have a fun time
implementing this with pipes.

At any rate, I have added your requests to my hg clone of the QtOctave
codebase:

     https://bitbucket.org/jordigh/qtoctave/issues

One further thing, by working with .NET, you are limiting your
contributions to the Windows world, unless you are making sure that
Mono is also able to compile and run your code. It won't be as much
use if release .NET source than if you use a true cross-platform
framework as Qt. I understand that perhaps this is your goal, and
while there is nothing wrong with being selfish, it is much better to
be generous towards other Octave users.

I am going to try one last time to dissuade you from going along this
route. You are repeating mistakes that other GUI authors have already
made; you are tying your work to a particular platform (unless you're
using Mono), you will most likely not reach the goal of creating the
GUI you want, and you will get bored/frustrated before you create what
you want. Instead, please invest the time it takes to understand
someone else's code and improve it. It is a much better long-term
investment if you are serious about giving Octave a good native GUI,
which is one of the most frequent requests from Octave users.

- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Redirecting Octave IO

Richard Crozier-2


On 06/02/2011 15:27, Jordi Gutiérrez Hermoso wrote:

> 2011/2/6 RC Crozier<[hidden email]>:
>> 1. select some text in the command window, press the F9 key and have it sent
>> to octave as a command.
> Okay, QtOctave doesn't do this one.
>
>> 2. select some text in an editor window, press the F9 key and have
>> it sent to octave as a command.
> Did you even try it? QtOctave implements this.
>
>> 3. have an editor window (with the above ability) with decent syntax
>> highlighting (I plan to implement this with scintillaNET, a .NET
>> control that wraps scintilla).
> QtOctave does have its own editor with its own syntax highlighting,
> but perhaps you consider it indecent.
>
>> 4. The ability to copy and paste text in the command window using
>> C-c and C-v, not currently possible in the windows console.
> QtOctave does this, in its weird way, because it's making the same
> mistake you are making and many other attempts at writing a GUI have
> made: sending output via a pipe (i.e. redirecting IO), instead of
> hooking onto the readline idle loop. OctaveDE is the only one I know
> that gets this right.
>
>> 5. The ability to step forward etc. when debugging by pressing one
>> of the F keys
> This is kind of implemented but not too well in QtOctave. Debugging is
> possible but awkward. And I think you're underestimating how difficult
> it is to get it working correctly. You won't have a fun time
> implementing this with pipes.
>
> At any rate, I have added your requests to my hg clone of the QtOctave
> codebase:
>
>       https://bitbucket.org/jordigh/qtoctave/issues
>
> One further thing, by working with .NET, you are limiting your
> contributions to the Windows world, unless you are making sure that
> Mono is also able to compile and run your code. It won't be as much
> use if release .NET source than if you use a true cross-platform
> framework as Qt. I understand that perhaps this is your goal, and
> while there is nothing wrong with being selfish, it is much better to
> be generous towards other Octave users.
>
> I am going to try one last time to dissuade you from going along this
> route. You are repeating mistakes that other GUI authors have already
> made; you are tying your work to a particular platform (unless you're
> using Mono), you will most likely not reach the goal of creating the
> GUI you want, and you will get bored/frustrated before you create what
> you want. Instead, please invest the time it takes to understand
> someone else's code and improve it. It is a much better long-term
> investment if you are serious about giving Octave a good native GUI,
> which is one of the most frequent requests from Octave users.
>
> - Jordi G. H.
>

Ok, well perhaps you have convinced me to desist for the time being at
least. Maybe I'll look into helping with qtoctave, I guess it does do
nearly what I want and I've now had a browse of the code, which perhaps
isn't as difficult as I thought it would be to understand. I would be
wanting to do my development in windows though, are there build
instructions available for this? I'm not against linux/unix by the way,
I work with it every day, but I am most interested in getting it to work
in windows where I am usually doing my development work.

There a couple more things I've noticed. First of all, for some reason,
automatic indenting in the editor adds huge spaces. My googling makes me
think you need to change the TabStopWidth property of the editor which
is 80 (pixels) by default to something smaller. 80 pixels is over 2cm, I
suggest something more like whatever the width of four characters in the
font used. In fact, it might be even better if you simply inserted four
space characters rather than a tab character like the matlab editor
does, as then the column number shown at the bottom would be more
accurate (i.e. is a tab character only one column? that is how it is
represented at the minute). I'm assuming this is what is being done
around line 184 and 226 of simpleeditor.cpp.

I don't really like the choices of colours and things in the editor for
m files, but I see now that this is controlled using an xml file and
have changed the preferences to something I prefer, so this is not
really a problem.

Another problem for me is that the debugging button on the editor
doesn't quite seem to do what I expect, but maybe I just don't now how
to do this properly yet.

p.s. perhaps I should no longer be posting this to the octave help? Not
sure what the correct etiquette is.

--
Richard Crozier, Research Associate
Institute for Energy Systems
School of Engineering and Electronics
The University of Edinburgh
Faraday Building, Room 4.124
The King’s Buildings
Edinburgh EH9 3JL

Phone: 0131 651 9023
Fax: 0131 650 6554


The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave