How to create a Linux file from oorexx?

Help
2009-04-10
2012-08-14
  • Maurice Batey
    Maurice Batey
    2009-04-10

    I've studied the rexxref.pdf file, but can find no explanation of how to create a Linux file!

    Presumably it's via CHAROUT or LINEOUT, but how are those functions linked into the Linux file system, that's the question...

     
    • Maurice Batey
      Maurice Batey
      2009-04-15

      > call lineout myFile, "This is my first line."

      Ah yes - of course - it's all coming abck to me now.
      I should have realised what the problem was. Sorry!

       
    • Mark Miesfeld
      Mark Miesfeld
      2009-04-10

      It's really pretty straight forward, you just write to it.

      It's no different than creating a file in Windows, if that is what is throwing you.

      The section under: Functions -> Builtin Functions -> Lineout() has some examples that work fine. (By the way, you should really upgrade to 3.2.0, a lot of improvement has been done since 3.1.2.)

      Here is a short, working example.

      / createFile.rex /

      myFile = 'anyfile.txt'
      call lineout(myFile, "This is my first line.")
      call lineout(myFile, "This is my second line.")
      call lineout(myFile)

      Cut and paste the above into a file and run it in your home directory, anyfile.txt will be created. (Provided it doesn't already exist. If it does exist, it will be appended to.)

      The only caveats are: you can not create a file where you do not have permission to. That is basically the same on any modern operating system.

      My take is you are still mostly using classic Rexx programming with ooRexx - which is perfectly fine. I didn't start using the 'object' part of Object Rexx for several years. But, here is the above using the stream object:

      myFileObject = .stream~new('someotherfile.txt')
      myFileObject~lineout("This is my first line")
      myFileObject~lineout("This is my seconds line")
      myFileObject~close

      In both cases you don't need to close the file at the end of the program, the interpreter will close the file(s) automatically when it ends.

      --
      Mark Miesfeld

       
    • Many thanks, Mark - much appreciated!

      Yes, I wrote a large suite of (classical) Rexx programs during my work on OS/2, but haven't touched Rexx since retiring 20 years ago, so I'm a little rusty, as well as not having interfaced Rexx with Linux before. But it's all coming back...

      Ny first encounter with Rexx was during the period when my colleague Mike Cowlishaw was putting the finishing touches to Rexx.
      That must have been 1980-1981.

      Regards,
      Maurice Batey
      www.maurice99.ukfsn.org

       
    • > ... you should really upgrade to 3.2.0 ...

      The 3.1.2 version I'm using was provided from Mandriva's software library. If 3.2.0 has been out very long then the new version will hopefully soon be offered by Mandriva's 'update' function.
      If not I'll oook for it on the ORexx site.

       
    • Mark Miesfeld
      Mark Miesfeld
      2009-04-11

      Maurice,

      Mandriva uses rpm so you can install an updated ooRexx without waiting for the Mandriva developers. 3.2.0 has been out for almost 18 months, so waiting for Madriva to update their software library seems, well, I don't have a good word for it. Seems unnecessary.

      rpm is easy to use from the command line. Plus, ooRexx 4.0.0 will soon be available, it seems like you might be waiting for years for Mandriva to have 4.0.0.

      You can download the rpm package from this project under the download tab. You uninstall the current version:

      rpm -e ooRexx

      and install the new version with:

      rpm -iv <package.rpm>

      For example:

      rpm -iv ooRexx-3.2.0-1.i386.rpm

      I doubt you would have any problem.

      --
      Mark Miesfeld

       
    • OK - thanks! Will do that tomorrow. 'night all...

       
    • Maurice Batey
      Maurice Batey
      2009-04-14

      > Here is a short, working example.
      >
      > / createFile.rex /

      > myFile = 'anyfile.txt'
      > call lineout(myFile, "This is my first line.")
      > call lineout(myFile, "This is my second line.")
      > call lineout(myFile)

      > Cut and paste the above into a file and run it in your home directory,
      > anyfile.txt will be created.

      Did exactly that, but it failed:

      rexx ~/scripts/ftest
      4 - call lineout(myFile, "This is my first line.")
      REX0037E: Error 37 running /home/mab/scripts/ftest line 4: Unexpected ",", ")", or "]"
      REX0365E: Error 37.1: Unexpected ","

      However, the OO version of the operation (in your example) works fine!

       
    • Maurice Batey
      Maurice Batey
      2009-04-14

      > You can download the rpm package from this project under the download tab

      Successfully downloaded and installed 3.2.0. Many thanks!

       
    • Mark Miesfeld
      Mark Miesfeld
      2009-04-14

      Sorry, I should have tested it. <grin>

      This is proper:

      / createFile.rex /

      myFile = 'anyfile.txt'
      call lineout myFile, "This is my first line."
      call lineout myFile, "This is my second line."
      call lineout myFile

      The thing is, I personally never use 'call'. I always use a function call syntax. So, I write the above as:

      / createFile.rex /

      myFile = 'anyfile.txt'
      j = lineout(myFile, "This is my first line.")
      j = lineout(myFile, "This is my second line.")
      j = lineout(myFile)

      You have to assign the return to something so it doesn't get passed to the operating system But, a lot of Rexx people would think my 'style' is not too 'Rexxish' so I converted it when I pasted it in and forgot the syntax then became wrong.

      I'm glad you installed 3.2.0 okay. It will then be easy for you to upgrade when 4.0.0 comes out.