comp.lang.ada
 help / color / mirror / Atom feed
* cannot write to a file in Linux despite +rw permissions
@ 2013-01-18 10:13 Ada novice
  2013-01-18 10:37 ` Jacob Sparre Andersen
  2013-01-18 10:59 ` Brian Drummond
  0 siblings, 2 replies; 9+ messages in thread
From: Ada novice @ 2013-01-18 10:13 UTC (permalink / raw)


Hello,
      I am a newbie in Linux and I have recently installed swiftlinux, which is Debian based. I am testing my Ada codes. They run well (I have put GNAT GPL 2011 for now), except that I see that I cannot write to text files. I have issued the command "chmod -R +rw" to the parent folder but that doesn't help and neither did running GPS as root help. 

If the compilation files are created and can be "destroyed" by the GPS clean command, this means that it should not be a problem to write to a text file. I also have LaTeX installed and I have no difficulty to generate a pdf file and modify it on subsequent compilation. 

So I am a bit puzzled that I cannot write to a file as an output of an Ada program. What happens is that the file gets created, say: "hi.text" but then it stays blank. I have tried to create the file "hi.txt" before running my Ada program in GPS but that is not helping also.

Here's a small code that I'm using (this works fine on Windows with the file and its contents created):

with Ada.Float_Text_IO;
with Ada.Text_IO; use Ada.Text_IO;


procedure Test_Writing is

   X                                             : Float := 3.0;
   Y                                             : Float := 2.0;


 Output_Data_File_All                            : File_Type;


 procedure Write_Files_All (Output_File          : File_Type;
                            Out_1           : Float;
                            Out_2           : Float;
                            Prec            : Natural := 3
                            ) is

        begin
             Ada.Float_Text_IO.Put (File => Output_File, Item => Out_1, Fore => 3, Aft => Prec, Exp => 0);
             Ada.Text_IO.Put (Output_File, "   ");

             Ada.Float_Text_IO.Put (File => Output_File, Item => Out_2, Fore => 3, Aft => Prec, Exp => 0);
             Ada.Text_IO.New_Line (Output_File);

       end Write_Files_All;



       begin
            Ada.Text_IO.Put ("Put file name to write for all elements: ");
            Create (Output_Data_File_All, Out_File, Get_Line);
            Ada.Text_IO.New_Line(1);

           for I in 1 .. 3 loop
           
             Ada.Float_Text_IO.Put (Item => X, Fore => 3, Aft  => 4, Exp  => 0);
             Ada.Float_Text_IO.Put (Item => Y, Fore => 3, Aft  => 5, Exp  => 0);
             Ada.Text_IO.New_Line (1);

             --write to file
             Write_Files_All (Output_Data_File_All,
                            Out_1 => x,
                            Out_2 => y
                            );

             X := X + 1.0;
             Y := Y + 2.0;

       end loop;

    Close (Output_Data_File_All);

end Test_Writing;

Since the code compiles and runs fine in GPS, I do not understand why the file cannot be written in the above case with the X and Y values.

Guess it must be something on Linux that I am not paying attention to.


Thanks for any suggestions.
YC 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: cannot write to a file in Linux despite +rw permissions
  2013-01-18 10:13 cannot write to a file in Linux despite +rw permissions Ada novice
@ 2013-01-18 10:37 ` Jacob Sparre Andersen
  2013-01-18 11:15   ` Ada novice
  2013-01-18 10:59 ` Brian Drummond
  1 sibling, 1 reply; 9+ messages in thread
From: Jacob Sparre Andersen @ 2013-01-18 10:37 UTC (permalink / raw)


YC wrote:

> I am a newbie in Linux and I have recently installed swiftlinux, which
> is Debian based. I am testing my Ada codes. They run well (I have put
> GNAT GPL 2011 for now), except that I see that I cannot write to text
> files.

You program looks correct (but ugly) and when I tested it here on my
machine it seemed to work as intended.  (I.e. created a file containing
three lines of two numbers.)

Please follow the style indicated in the Ada Quality and Style Guide.

And please don't declare global variables before the bodies of
operations which don't need access to them.

Greetings,

Jacob
-- 
"The butcher backed into the meat grinder and got a little behind
 in his work."



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: cannot write to a file in Linux despite +rw permissions
  2013-01-18 10:13 cannot write to a file in Linux despite +rw permissions Ada novice
  2013-01-18 10:37 ` Jacob Sparre Andersen
@ 2013-01-18 10:59 ` Brian Drummond
  2013-01-18 11:19   ` Ada novice
  1 sibling, 1 reply; 9+ messages in thread
From: Brian Drummond @ 2013-01-18 10:59 UTC (permalink / raw)


On Fri, 18 Jan 2013 02:13:55 -0800, Ada novice wrote:

> Hello,
>       I am a newbie in Linux and I have recently installed swiftlinux,
>       which is Debian based. I am testing my Ada codes. They run well (I
>       have put GNAT GPL 2011 for now), except that I see that I cannot
>       write to text files. I have issued the command "chmod -R +rw" to
>       the parent folder but that doesn't help and neither did running
>       GPS as root help.

> Since the code compiles and runs fine in GPS, I do not understand why
> the file cannot be written in the above case with the X and Y values.
> 
> Guess it must be something on Linux that I am not paying attention to.

Works fine here (OpenSuse 11.3)
gnatmake --version
GNATMAKE 4.6.3 20120531 [gcc-4_6-branch revision 188067]
Copyright (C) 1995-2011, Free Software Foundation, Inc.

Check you are using the Gnat you think you are :
 which gnatmake
/usr/bin/gnatmake

In my case, that's the distribution's own (what you would get by typing
sudo apt-get install gnat
on Debian) I think the Adacore one would be in /usr/gnat/bin.

The system will use whichever is first in the path; you can modify it as 
follows:

echo $PATH
/home/brian/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games

export PATH=/usr/gnat/bin:$PATH

echo $PATH
/usr/gnat/bin:/home/brian/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/
usr/X11R6/bin:/usr/games:

which gnatmake
/usr/gnat/bin/gnatmake

Here, both work on your test. But it is possible you have a broken 
install from Swiftlinux so it may be worth checking.

- Brian





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: cannot write to a file in Linux despite +rw permissions
  2013-01-18 10:37 ` Jacob Sparre Andersen
@ 2013-01-18 11:15   ` Ada novice
  0 siblings, 0 replies; 9+ messages in thread
From: Ada novice @ 2013-01-18 11:15 UTC (permalink / raw)


On Friday, January 18, 2013 11:37:08 AM UTC+1, Jacob Sparre Andersen wrote:

> 
> You program looks correct (but ugly) and when I tested it here on my

Yes this is just a short program that I'm testing.

 
> 
> Please follow the style indicated in the Ada Quality and Style Guide.
> 

Yes it is a good reference

>
>  
> 
> Jacob





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: cannot write to a file in Linux despite +rw permissions
  2013-01-18 10:59 ` Brian Drummond
@ 2013-01-18 11:19   ` Ada novice
  2013-01-18 15:44     ` Ada novice
  0 siblings, 1 reply; 9+ messages in thread
From: Ada novice @ 2013-01-18 11:19 UTC (permalink / raw)


On Friday, January 18, 2013 11:59:18 AM UTC+1, Brian Drummond wrote:


> Here, both work on your test. But it is possible you have a broken 
> 
> install from Swiftlinux so it may be worth checking.
> 
> 
> 
> - Brian


Thanks. It has nothing to do with the path. I have it right with which gnatmake both on my user profile and on the root. I have put the GNAT 2011 in /usr/bin/local/gnat-2011 (if I remember right, I am on my other machine now). There is just one Ada installation and all path are referenced well both on my user profile and on the root.

I must look again at the text file created and see if its permissions are being modified somehow at some stage. 

Thanks
YC



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: cannot write to a file in Linux despite +rw permissions
  2013-01-18 11:19   ` Ada novice
@ 2013-01-18 15:44     ` Ada novice
  2013-01-18 23:36       ` Brian Drummond
  0 siblings, 1 reply; 9+ messages in thread
From: Ada novice @ 2013-01-18 15:44 UTC (permalink / raw)


I have tracked the problem. It is working fine now. On Windows while GPS is running, I can terminate the application with the cross X located in GPS at the bottom right. The text file stops being written and if I open the text file, then I can see the values wriiten up till when I terminate the program.

On my Linux, if I press the terminate button in GPS while the program is still running and the file is being written, something happens so that the text file does not keep the values wriiten so far. This is why I was getting a blank text file. 

I was not noticing this as I was running a complex program that takes long to run. But when I tried my small code and it worked, this gave me some hint.

Problem solved!

YC



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: cannot write to a file in Linux despite +rw permissions
  2013-01-18 15:44     ` Ada novice
@ 2013-01-18 23:36       ` Brian Drummond
  2013-01-19  7:08         ` Ada novice
  0 siblings, 1 reply; 9+ messages in thread
From: Brian Drummond @ 2013-01-18 23:36 UTC (permalink / raw)


On Fri, 18 Jan 2013 07:44:03 -0800, Ada novice wrote:

> I have tracked the problem. It is working fine now. On Windows while GPS
> is running, I can terminate the application with the cross X located in
> GPS at the bottom right. The text file stops being written and if I open
> the text file, then I can see the values wriiten up till when I
> terminate the program.
> 
> On my Linux, if I press the terminate button in GPS while the program is
> still running and the file is being written, something happens so that
> the text file does not keep the values wriiten so far. This is why I was
> getting a blank text file.

The file is probably only flushed on exit or if you programmed a specific 
flush operation (or Close). If you were terminating the program 
abnormally (e.g. in a debugger), that may not have been happening. I was 
simply running from the command line and letting it exit...

> Problem solved!

I'm glad!

- Brian



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: cannot write to a file in Linux despite +rw permissions
  2013-01-18 23:36       ` Brian Drummond
@ 2013-01-19  7:08         ` Ada novice
  2013-01-19 10:11           ` Brian Drummond
  0 siblings, 1 reply; 9+ messages in thread
From: Ada novice @ 2013-01-19  7:08 UTC (permalink / raw)


I realized that I was putting you all on the wrong track since I was experimenting on a more complex Ada code that takes time to run than on the very simple code that I posted here, which made you believe that it could be a GNAT installation issue. My apologies for this. I was tempted to believe that it was a file permissions issue!

YC



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: cannot write to a file in Linux despite +rw permissions
  2013-01-19  7:08         ` Ada novice
@ 2013-01-19 10:11           ` Brian Drummond
  0 siblings, 0 replies; 9+ messages in thread
From: Brian Drummond @ 2013-01-19 10:11 UTC (permalink / raw)


On Fri, 18 Jan 2013 23:08:53 -0800, Ada novice wrote:

> I realized that I was putting you all on the wrong track since I was
> experimenting on a more complex Ada code that takes time to run than on
> the very simple code that I posted here, which made you believe that it
> could be a GNAT installation issue. My apologies for this. I was tempted
> to believe that it was a file permissions issue!

No apology needed. If "works here, mate" is just the poke you need to 
(try the trivial example and) look elsewhere, then it served its purpose. 
If there's a lesson it is that you could shorten the loop next time...

- Brian




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-01-19 10:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-18 10:13 cannot write to a file in Linux despite +rw permissions Ada novice
2013-01-18 10:37 ` Jacob Sparre Andersen
2013-01-18 11:15   ` Ada novice
2013-01-18 10:59 ` Brian Drummond
2013-01-18 11:19   ` Ada novice
2013-01-18 15:44     ` Ada novice
2013-01-18 23:36       ` Brian Drummond
2013-01-19  7:08         ` Ada novice
2013-01-19 10:11           ` Brian Drummond

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox