With LEAPWORK, there are instances when the user is required to perform the Text read and write operations on a text file like notepad.
Users can achieve this functionality easily by using the command line building block in LEAPWORK. Users can trigger a PowerShell script using this block which will perform the read/write operations. In Powershell, we do have commands which are very helpful to achieve the above scenarios.
Note: Click Here to get a better insight into how to run Powershell scripts using the Command Line building block works.
Read text using PowerShell
To read the text from the notepad, the user should type the below command in a text file and save it as a PowerShell file i.e. file with ps1 extension where "filepath" is the complete path of the text file from where the text is to be read.
Get-Content -Path "filepath"
After the file is saved, now we need to trigger that file using the command line building block in LEAPWORK. to do so, please follow the below screenshot and make sure to change the method type to 'Get as text' as highlighted in the screenshot below:
Writing text using Powershell
To write the text to a notepad file, the customer should type the below command in a text file and save it as a PowerShell file i.e. file with ps1 extension where "filepath" is the complete path of the text file where the user is required to write the text.
Add-Content "filepath" "Text"
After the file is saved, now the user needs to trigger that file using the command line building block in LEAPWORK. to do so, please follow the below screenshot and make sure to change the method type to 'Get as text' as highlighted in the screenshot below:
For any clarification, please contact our Priority Support.
Comments
0 comments
Please sign in to leave a comment.