Aksh Contributor.
Contributor.
353 views

Write To File operation issue

Hi,

I am facing an issue while using Write To File ("windows only" one ) operation.

In a workflow I am using Read File operation to read 5 servers from a file. They are stored like this.

10.0.0.0
0.0.0.0
10.0.0.18
1.1.1.1
10.0.0.11

Then, I am using Ping operation to check if the server is up or not. If the Ping is successful, I am writing that server IP to a file. If unsuccessful, writing it to a different file.

But, while writing, The server IPs are appending in the file with a newline by themselves. Even when I am not giving any delimiter value. and keeping overwrite false. Like this,

10.0.0.18

10.0.0.11

(in one file,as these are giving ping successful,and)

0.0.0.0

1.1.1.1

10.0.0.0

(these are unsuccessful.)

Problem worsens when executing the flow multiple times.(appending in the same files again.)

Any solution for this ?

** I also tried this by replacing the write to file operation with the powershell script operation and providing the script input with " ${Server IP} | Out-File -FilePath ${FilePath} -Append".  Even that is giving the same problem.

 

Thanks & Regards,

Aksh.

0 Likes
4 Replies
AndreiTruta Outstanding Contributor.
Outstanding Contributor.

Re: Write To File operation issue

did you try to strip the newline char before writing to the file?

can you provide a snapshot of how you are wrting to file?

Andrei Vasile Truta
0 Likes
Aksh Contributor.
Contributor.

Re: Write To File operation issue

Hi Andrei,

Thank you for your response.

By mistake I mentioned that in case of Write To File operation, I am getting a newline when appending to the file. Apologies for that.

Although, that is the problem while using powershell script operation, but in write to file operation I am facing a different issue.

In case of Write to File, the first execution of the flow is providing me with desirable result, i.e

10.0.0.18
10.0.0.11

in one file,and

10.0.0.0
0.0.0.0
1.1.1.1

But, in second execution of the flow, the results are :

10.0.0.18
10.0.0.1110.0.0.18
10.0.0.11

in the first file,and

10.0.0.0
0.0.0.0
1.1.1.1
10.0.0.0
0.0.0.0
1.1.1.1

in the second file

So, "10.0.0.1110.0.0.18" this scenario in the first case is the issue here.

I am attaching the snapshot of the flow. In the write to file operation, I am giving these inputs:-

-file : filepath of the file I want to append to

-contents : a variable holding the output of the Read File operation (the IP address of the machines in each iteration)

-delimiter : "Providing Enter"

-overwrite : false

all other inputs are left blank.

0 Likes
AndreiTruta Outstanding Contributor.
Outstanding Contributor.

Re: Write To File operation issue

I am able to making it work as below.

Screenshot_31.png

Andrei Vasile Truta
0 Likes
Aksh Contributor.
Contributor.

Re: Write To File operation issue

Hi,

You are directly passing the IPs in the content input here.

Try to pass the IPs from a text file, by reading them from Read File operation, and then passing a flow variable as input in the content input.

As in my case, Read File operation reads each IP in an iteration. Stores the IP in a result named "xyz". Passess the variable to the Ping operation. Then, if the ping is success, the IP currently in the variable gets stored in a file (pass the variable in content input of write to file operation). If ping is unsuccessful, the IP is stored in another file.

Regards,

Aksh

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.