By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,401 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,401 IT Pros & Developers. It's quick & easy.

Dynamically updating a container from a text file

P: 25
Hi all
I am using WScript.Shell in order to execute a batch file that runs a few commands with a large output that is redirected to a local text file.
When execution is finished, I read the text file and update a scrolling DIV on my html page with the output from the batch file.
Something like this:

Expand|Select|Wrap|Line Numbers
  1. Cmd="%comspec% /c script.bat > c:\output.txt"
  2. Exec=WshShell.Run(Cmd,0, true); 
  3. fso = new ActiveXObject("Scripting.FileSystemObject");
  4. ts = fso.OpenTextFile("C:\\output.txt", 1);
  5. msg = ts.ReadAll();
  6. var output = document.createElement('font');
  7. output.innerHTML=msg;
  8. div.appendChild(output);
  9.  
Thing is, this takes a long time and until the execution is finished, I cannot follow the log file to see what's going on.
My question is :
Is there anyway I can dynamically update my div with the content of the growing text file ?
Any suggestions will be great !

Thanks
Dec 29 '08 #1
Share this Question
Share on Google+
12 Replies


gits
Expert Mod 5K+
P: 5,390
just to confirm - this is just a local running application?

kind regards
Dec 29 '08 #2

P: 25
This is an intranet web page, on a local server running apache.
It is for internal use only.
No problem writing and reading from client file system.
Dec 29 '08 #3

gits
Expert Mod 5K+
P: 5,390
but the wsh-script runs locally on every client? you might try an ajax-call to the local file ... may be some security restrictions might occur and have to be adjusted.
Dec 29 '08 #4

P: 25
Can you please elaborate on the 'ajax-call to the local file' bit ?
I'm not sure I understand.
I thought ajax was a way to get info from the server.
What I need is to access a file on the client.

TIA
Dec 29 '08 #5

gits
Expert Mod 5K+
P: 5,390
typically you are right ... but you do untypical things and so we might use untypical things too ;) ... the ajax-call is to be send to an url:

Expand|Select|Wrap|Line Numbers
  1. xmlHttp.open('GET', 'url', true);
where url could even be a local txt-file. there could be issues with cross-domain requests but those could be solved with security policies for the IE in your intranet i guess.

kind regards
Dec 29 '08 #6

P: 25
Sorry for being difficult but I still don't realy understand.
Do you mean I can read a local text file using ajax ?
If so, please demonstrate how.

Thanks
Dec 29 '08 #7

gits
Expert Mod 5K+
P: 5,390
ok ... here you go with FF ;)

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <script type="text/javascript">
  3.  
  4. function get_data() {
  5.     var xmlHttp = new XMLHttpRequest;
  6.  
  7.     xmlHttp.onreadystatechange = function() {
  8.         if (xmlHttp.readyState == 4) {
  9.             alert(xmlHttp.responseText);
  10.         }
  11.     }
  12.  
  13.     xmlHttp.open('GET', 'foo.txt', true);
  14.     xmlHttp.send(null);
  15. }
  16.  
  17. </script>
  18.  
  19. <body onload="get_data();">
  20. </body>
  21. </html>
  22.  
just put a file 'foo.txt' relative to this html file and write some text into it. the alert should show you the content of this file. i'll try it with IE too ...

kind regards
Dec 29 '08 #8

gits
Expert Mod 5K+
P: 5,390
for IE this should work too ... but you need to instantiate the

ActiveXObject("Microsoft.XMLHTTP");

or

ActiveXObject("Msxml2.XMLHTTP")

accordingly.
Dec 29 '08 #9

P: 25
This looks good, thanks!

So, will ajax calls allow me to read the file while the WshShell command is updating it ?
Dec 29 '08 #10

gits
Expert Mod 5K+
P: 5,390
the webpage needs to start the ajax-call so you might use setInterval() to read the file from time to time ... you have to try it ... because i'm not quite sure whether there could be a file-access problem when the wsh uses or needs exclusive rights to write the file? i'm not quite familiar with those MS-things ;)

kind regards
Dec 29 '08 #11

P: 25
Thanks. I will try ...

BTW - do you know of a better way to execute commands on a client other than the WshShell method ?

Of course, any method would have to be able to save the output somewhere.
Dec 29 '08 #12

gits
Expert Mod 5K+
P: 5,390
well ... let us now whether it works or not ;) ... and unfortunatly i think i wouldn't have another idea besides the WSH on windows ... except that the entire task could be done in another way ... so something like transfering the data in question to the server and provide it from there instead of using a local file at the client ... as i said it seems quite strange to use client ressources from a webpage but in case you need it then it could be done of course :) ... we do some of such things with FF here for our applications ... so it is not strange enough to say - don't do it ... and i think for an internal app it is ok to do such things ...

kind regards
Dec 29 '08 #13

Post your reply

Sign in to post your reply or Sign up for a free account.