* How to use/obtain output from system commands (in an Ada program) ?
@ 2016-06-19 6:08 reinkor
2016-06-19 7:23 ` Dmitry A. Kazakov
0 siblings, 1 reply; 9+ messages in thread
From: reinkor @ 2016-06-19 6:08 UTC (permalink / raw)
Hi,
I am looking for a simple way to obtain output from "xmessage"
(or dialog/kdialog) in my Ada program. Any good hints?
A trivial way is to output to a file like in this test procedure:
with Interfaces.C;
with Interfaces.C.Strings;
with Ada.Text_IO, Text_IO;
procedure Test7 is
package C renames Interfaces.C;
use type C.char_array;
procedure system (Source : in C.char_array);
pragma Import(C, system, "system");
use Ada.Text_IO, Text_IO;
file1 : File_Type;
begin
system("xmessage -center Box1 -buttons label1:X,label2:y -print > choice_file1");
Open(file1,In_File,"choice_file1");
declare
A : String := Get_Line(file1);
begin
Put(" Choice: " & A);
end;
Close(file1);
end Test7;
Are there more direct/better ways?
** By the way: when I run this program on Raspberry Pi
(lastest Raspbian jessie) i get, as expected, created the file "choice_file1".
Under OpenSuse Leap 42.1, gnat-5, i get produced a file named:
"choice_file1choice_file1test7.adb". Strange?
reinert
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to use/obtain output from system commands (in an Ada program) ?
2016-06-19 6:08 How to use/obtain output from system commands (in an Ada program) ? reinkor
@ 2016-06-19 7:23 ` Dmitry A. Kazakov
2016-06-20 8:34 ` reinkor
2016-06-22 8:14 ` briot.emmanuel
0 siblings, 2 replies; 9+ messages in thread
From: Dmitry A. Kazakov @ 2016-06-19 7:23 UTC (permalink / raw)
On 2016-06-19 08:08, reinkor wrote:
> I am looking for a simple way to obtain output from "xmessage"
> (or dialog/kdialog) in my Ada program. Any good hints?
The package System.OS_Lib has procedures Spawn that are much more
comfortable to use than system().
If you use GtkAda you can start xmessage or any other process with
pipe-lined input/output/error. Then you will have callbacks to process
them. It is also possible to use Gtk_Text_Buffer instead of callbacks.
http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm#10.1
> A trivial way is to output to a file like in this test procedure:
>
> with Interfaces.C;
> with Interfaces.C.Strings;
> with Ada.Text_IO, Text_IO;
>
> procedure Test7 is
> package C renames Interfaces.C;
> use type C.char_array;
> procedure system (Source : in C.char_array);
> pragma Import(C, system, "system");
> use Ada.Text_IO, Text_IO;
> file1 : File_Type;
> begin
> system("xmessage -center Box1 -buttons label1:X,label2:y -print > choice_file1");
Add terminating ASCII NUL here.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to use/obtain output from system commands (in an Ada program) ?
2016-06-19 7:23 ` Dmitry A. Kazakov
@ 2016-06-20 8:34 ` reinkor
2016-06-20 8:44 ` Dmitry A. Kazakov
2016-06-22 8:14 ` briot.emmanuel
1 sibling, 1 reply; 9+ messages in thread
From: reinkor @ 2016-06-20 8:34 UTC (permalink / raw)
Thanks a lot,
any hint about rpm/repository for gtkada on OpenSuse (Leap) ?
reinert
On Sunday, June 19, 2016 at 9:24:16 AM UTC+2, Dmitry A. Kazakov wrote:
> On 2016-06-19 08:08, reinkor wrote:
>
> > I am looking for a simple way to obtain output from "xmessage"
> > (or dialog/kdialog) in my Ada program. Any good hints?
>
> The package System.OS_Lib has procedures Spawn that are much more
> comfortable to use than system().
>
> If you use GtkAda you can start xmessage or any other process with
> pipe-lined input/output/error. Then you will have callbacks to process
> them. It is also possible to use Gtk_Text_Buffer instead of callbacks.
>
> http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm#10.1
>
> > A trivial way is to output to a file like in this test procedure:
> >
> > with Interfaces.C;
> > with Interfaces.C.Strings;
> > with Ada.Text_IO, Text_IO;
> >
> > procedure Test7 is
> > package C renames Interfaces.C;
> > use type C.char_array;
> > procedure system (Source : in C.char_array);
> > pragma Import(C, system, "system");
> > use Ada.Text_IO, Text_IO;
> > file1 : File_Type;
> > begin
> > system("xmessage -center Box1 -buttons label1:X,label2:y -print > choice_file1");
>
> Add terminating ASCII NUL here.
>
> --
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to use/obtain output from system commands (in an Ada program) ?
2016-06-19 7:23 ` Dmitry A. Kazakov
2016-06-20 8:34 ` reinkor
@ 2016-06-22 8:14 ` briot.emmanuel
1 sibling, 0 replies; 9+ messages in thread
From: briot.emmanuel @ 2016-06-22 8:14 UTC (permalink / raw)
> > I am looking for a simple way to obtain output from "xmessage"
> > (or dialog/kdialog) in my Ada program. Any good hints?
Look at the package GNAT.Expect, which is meant to spawn an
executable while keeping pipes for its input and output. You do not have
to go through a file for this.
It is used by GPS to spawn compiler, interactive debugger,...
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2016-06-22 8:14 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-19 6:08 How to use/obtain output from system commands (in an Ada program) ? reinkor
2016-06-19 7:23 ` Dmitry A. Kazakov
2016-06-20 8:34 ` reinkor
2016-06-20 8:44 ` Dmitry A. Kazakov
2016-06-20 9:22 ` reinkor
2016-06-20 9:59 ` Dmitry A. Kazakov
2016-06-20 19:25 ` reinkor
2016-06-20 19:55 ` Dmitry A. Kazakov
2016-06-22 8:14 ` briot.emmanuel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox