Batch script executed from InTouch doesn't generate output

gardarog

Member
Join Date
Jul 2015
Location
Egilsstadir
Posts
23
I've developed a simple batch script to test communications with a couple of ethernet devices one of our clients has out in the field.

The script pings a static IP address and prints the result to a text file.
I've tested the script thoroughly, and it works like a charm.
The script (e.g. ping14.bat) generates a text file (ping14result.txt) in it's containing directory, with a value to indicate if the ping was successful or not.

I've made a network diagram in the client's Wonderware InTouch 10.6 SCADA application, which displays the various field devices, and has a button to check comms for each one.

The button runs an action script, calling the batch script:

StartApp "c:\bat\ping14.bat";

The button has a green indicator if the device responded to the ping, and a red blinking indicator if the device was unresponsive.
I'm using a continuous FileReadMessage() built-in function in the window script to read the value contained in the text file generated by the .bat script to a Memory Message tag.

FileReadMessage ("c:\bat\ping14result.txt",0,ping14result, 0);

The indicator works fine, and returns the correct value from the text file to the message tag.

HOWEVER:

When the InTouch button is used to trigger the script, the script doesn't generate output.

Let's say I delete the text file, ping14result.txt.

I then go to the running InTouch application and use the button to run the .bat script.
I get a flashing CMD prompt on my screen, so everything looks OK.
I then go to the directory to check the .txt file, and there's nothing there.
I've also tried adding "pauses" in the batch script before and after the result is printed to the text file, to make sure the problem is not due to the script not completing it's execution.

pause
@echo %result%> ping14result.txt
pause


And the result was the same.

Now, if I double click the .bat file from windows explorer, everything works fine.
The .txt file is generated if needed, and it's values overwritten if it's already in place.

I've also tried running the .bat script by calling it from the command prompt and it runs fine.

Now I'm wondering what could be causing this?
I've tried removing the FileReadMessage() code from the window script, to make sure that WindowViewer isn't reserving the .txt files and preventing them from being overwritten, with no luck...o_O
Has anyone seen this kind of behaviour before?
 
Last edited:
You may try the WWDosCommand function instead of StartApp. The script function WWDosCommand, can be found in Wonderware Tech Support Script Function Library online or on the Knowledgebase CD.
Else I would rather use some network monitoring software. By experience constantly writing, reading and deleting files within InTouch scripts sooner or later cause problems.
 
Thanks xzen, I gave that ago earlier today, using the WWDosCommand to run the .bat script.
I even tried using the WWDosCommand instead of the .bat script to perform the ping and output to a text file, with little luck.
There's something fishy going I here...
Do you have experience working with outputs in this manner, and have you had better results?
 
I use the WWDosCommand to get the PC's IP address using a batch file. Basically:
ipconfig /all > ip.txt
But then I have found that that file wont show up instantly and I had to use some condition scripting to poll for that file, then get the IP address out of it.
 
A couple of things to check for.

A .bat (batch) file isn't executionable by itself. It needs the command interpreter to interpret and execute the batch file. That happens by itself when you execute it from a dos prompt (because a dos prompt IS cmd.exe, the actual command interpreter in Windows).

It might not happen from within InTouch. It depends on what the developers did. So to explicitly execute a batch file you can use cmd.exe /c batfile.bat. You can also explicitly specify the path to cmd.exe.


Second thing to check is that the Intouch application is running under a specific user account. For your bat file to be able to actually write to the disc the Intouch user must have the rights to write to that directory.

Third thing to check is to check that you are using absolute paths to the files. If you create a file make sure it's specified otherwise the file will end up in different directories depending on the working directory. That would be different when run from the command prompt or from within Intouch.
 
Last edited:
A couple of things to check for.
Third thing to check is to check that you are using absolute paths to the files. If you create a file make sure it's specified otherwise the file will end up in different directories depending on the working directory. That would be different when run from the command prompt or from within Intouch.

Oh my god... Absolute paths...
I changed my .bat script so that it would output the ping result like so:

@echo %result%> c:\bat\ping14result.txt

instead of:

@echo %result%> ping14result.txt

And that did the trick.
Thank you all for your input, and you Pete for easing my headache!
 

Similar Topics

Hello I have a folder that has txt files added as reports is ran. By default these reports is saved as a .txt file and no way to change this...
Replies
25
Views
11,540
Hi guys I have had a thought regarding a quick hmi screen change for none experienced staff , is there a way that we can have a sd card or a usb...
Replies
1
Views
1,257
Can any one write script / batch commands ?? Iknow its not a PLC question but it is related in a way. This is for use at work with the...
Replies
2
Views
3,153
Hi Everyone, Thought I had it figured out but I came to the conclusion it would not work. Here is what I'm working with... 1769-L30ER Flow Meter...
Replies
24
Views
614
Does anyone have expereince creating a custom API to build a campaign management system for FactoryTalk Batch? Stuck between using a REST API or...
Replies
0
Views
444
Back
Top Bottom