UiPath has various input-output activities that help us build attended automation where the bot takes input and shows output to users in various forms.
One of the activities that output information to the console is WriteLine.
We would have used this many times by now for printing some text in the UiPath Studio output console.
UiPath WriteLine Text |
UiPath WriteLine TextWriter |
As we know, UiPath is built on .NET. So, let's discuss this in .NET way for a while.
WriteLine in .NET
Please go through what is .NET class & functions which will help you understand the below explanation better.
WriteLine is a dotnet function/method defined under three classes,
System.Console.WriteLine is a function which helps in outputting text to the console (By default this is what we are using in UiPath WriteLine)
Now let's say you want to change the output from the console to something else like a file or blob may be...
This is when the other two classes come into the picture.
About TextWriter
In WriteLine since we are only passing value to the Text field leaving the TextWriter property empty, it assumes the default source is the console and hence printing output in the console.
Let's mention some sources this time in TextWriter. Considering a text file is the place to write the text.
Let's try to write hello world in a text file source using Write Line (which is already created).
StreamWriter with file path will create a buffer in memory so that we can perform a write operation to that file.
The above tech jargons are purely related to .NET, and knowing that helps. If it is confusing just skip to just understand the usage of WriteLine.
UiPath WriteLine TextWriter |
The automation executed well & it was not printing in the console panel.
But still, the text file source is empty :(
So there is a catch here to be taken care of.
As we discussed, StreamWriter is going to just create a memory buffer for performing the file operation. But we still need to close it which is why it is not getting stored in the file.
To make it work, we need to just Flush it.
Please feel free to add your points & queries over comments.
Reference - https://github.com/nmnithinkrishna/UiPath-WriteLine-TextWriter
No comments:
Post a Comment
Let me hear you 🙌✨