Howto: Writing formatted text (from a variable) to a file

Last post 06-23-2017, 8:28 AM by cwsunderland. 3 replies.
Sort Posts: Previous Next
  • Howto: Writing formatted text (from a variable) to a file
    Posted: 06-21-2017, 5:44 AM


    Is there already some code/custom activity to write/append a variable to a (windows)file?



  • Re: Howto: Writing formatted text (from a variable) to a file
    Posted: 06-21-2017, 4:25 PM

    Hey Mark, are you wanting to just append a line to a file on the local machine?  If so, you can use a Script activity like below to append a line to a file.  You can also create a Custom Script activity with this code if you need to use it in multiple places.


    File file = new File("c:\\temp\\file.txt");
    if (!file.exists())
    FileWriter writer = new FileWriter(file, true);
    writer.write("new line in file\n");

    The highlighted items can be replaced with your requirements and/or variables.


  • Re: Howto: Writing formatted text (from a variable) to a file
    Posted: 06-22-2017, 12:28 PM

    That works on the local disks, but I have also to write to another server like \\server\share\path\file.ext

    How can I  use apply usercredentials (usr+psw) on such an activity?

  • Re: Howto: Writing formatted text (from a variable) to a file
    Posted: 06-23-2017, 8:28 AM

    To do this you'll need to use activities that allow impersonation like ExecuteCommand and ExecuteScript.  For instance you could use ExecuteScript with the Batch script type along with an administrator impersonation to pipe text to a file:

    echo xpath:{...} >> \\server\share\path\file.ext

    Also you maybe can execute the Script on the remote server directly and not have to pipe it across a share

    echo xpath:{...} >> c:\path_to_share\path\file.ext


The content of the forums, threads and posts reflects the thoughts and opinions of each author, and does not represent the thoughts, opinions, plans or strategies of Commvault Systems, Inc. ("Commvault") and Commvault undertakes no obligation to update, correct or modify any statements made in this forum. Any and all third party links, statements, comments, or feedback posted to, or otherwise provided by this forum, thread or post are not affiliated with, nor endorsed by, Commvault.
Commvault, Commvault and logo, the “CV” logo, Commvault Systems, Solving Forward, SIM, Singular Information Management, Simpana, Commvault Galaxy, Unified Data Management, QiNetix, Quick Recovery, QR, CommNet, GridStor, Vault Tracker, InnerVault, QuickSnap, QSnap, Recovery Director, CommServe, CommCell, SnapProtect, ROMS, and CommValue, are trademarks or registered trademarks of Commvault Systems, Inc. All other third party brands, products, service names, trademarks, or registered service marks are the property of and used to identify the products or services of their respective owners. All specifications are subject to change without notice.
Copyright © 2020 Commvault | All Rights Reserved. | Legal | Privacy Policy