Uploaded image for project: 'Forge'
  1. Forge
  2. FORGE-1860

Writing files with content

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Unresolved
    • Icon: Major Major
    • 3.x Future
    • 2.6.0.Final
    • UI - Shell
    • None

      I see myself adding files here and there on my projects (JBoss cli commands, shell scripts, SQL scripts...) and I use the touch command in Forge extensively. But how could I add content to these files ? I mostly write Forge scripts, so I would love to do something like that in my script :

      # Creates a project
      project-new --named test
      
      # Adds a few extra files and directories
      
      mkdir src/main/script ;
      touch src/main/resources/insert.sql ; // This creates an empty file
      touch src/main/script/wildfly-show.cli --content (((( // This adds content to the file
      
          version
          # ####################
          # #  System Properties
          # ####################
      
          /core-service=platform-mbean/type=runtime:read-attribute(name=system-properties)
      
          # ####################
          # #  Datasource
          # ####################
      
          /subsystem=datasources/data-source=ApplicationBlancheH2DS:read-resource
      ))))
      

      And this command would just create a file with the previous content in it. As you can see, this can be tricky : when to end the content of a file (something similar to <![CDATA[]]>)

      George mentioned on the mailing list :

      I think piping to a file would be more intuitive and it should work now:

      echo Hi > a.txt
      

      The problem with this, is I can't make it work the way I want. In fact, each time I do a echo text > file.txt, the file.txt is created in the directory below, not the current one. As I can't create a file in another directory.

      [Devoxx]$ ls
      
      [Devoxx]$ project-new --named testecho
      ***SUCCESS*** Project named 'testecho' has been created.
      [testecho]$ ls
      pom.xml  src
      
      [testecho]$ echo Text to add to this new file > newfile.txt
      [testecho]$ ls
      pom.xml  src
      
      [testecho]$ cd ..
      [Devoxx]$ ls
      newfile.txt  testecho
      
      [Devoxx]$
      [testecho]$ echo One test again > ./file.txt
      [testecho]$ ls
      pom.xml  src
      

            Unassigned Unassigned
            agoncal Antonio Goncalves (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: