ReneGe
asked on
Java Script: Output to file
Hi there,
I need to modify the included script so it output's to a file by it self, not through the batch file.
It is currently called from a batch file using cscript as follows:
cscript websitemonitor.js "www.websitetomonitor.com">websitetomonitor.com.tx t
The new script will be called like this and the output file will be presented as an argument:
cscript websitemonitor.js "www.awebsite.com" "awebsite.com.txt"
Thanks for your help,
Rene
I need to modify the included script so it output's to a file by it self, not through the batch file.
It is currently called from a batch file using cscript as follows:
cscript websitemonitor.js "www.websitetomonitor.com">websitetomonitor.com.tx
The new script will be called like this and the output file will be presented as an argument:
cscript websitemonitor.js "www.awebsite.com" "awebsite.com.txt"
Thanks for your help,
Rene
var request = new ActiveXObject("Msxml2.XMLHTTP");
var notyetready = 1;
request.onreadystatechange=function()
{
if(request.readyState==4)
{
WScript.Echo(request.responseText);
notyetready = 0;
}
}
var objArgs = WScript.Arguments;
WScript.Echo("objArgs(0)");
request.open( "GET", "objArgs(0)" , true );
request.send(null);
while( notyetready )
{
WScript.Sleep( 100 );
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
mplungjan,
Your script does not work
Since I don't know Java Script. Please provide me with the complete solution, not suggestions.
Thanks and cheers,
Rene
Your script does not work
Since I don't know Java Script. Please provide me with the complete solution, not suggestions.
Thanks and cheers,
Rene
"does not work" is not very helpful :(
Can you tell me if you get any error messages, and if so, which ones. Is the folder you run the script have write permissions
Since I do not have access to a windows PC until tomorrow, I could not test the script and it was not obvious from your question that you did not know JS.
I will try testing this tomorrow unless someone comes along before with a working solution.
Can you tell me if you get any error messages, and if so, which ones. Is the folder you run the script have write permissions
Since I do not have access to a windows PC until tomorrow, I could not test the script and it was not obvious from your question that you did not know JS.
I will try testing this tomorrow unless someone comes along before with a working solution.
ASKER
Here is the error message:
WebsiteMonitor.vbs(1, 32) Microsoft VBScript compilation error: Expected end of statement.
Thanks for helping.
Cheers,
Rene
WebsiteMonitor.vbs(1, 32) Microsoft VBScript compilation error: Expected end of statement.
Thanks for helping.
Cheers,
Rene
Does the script you ran beforehand look exactly like you posted it ?
vbs is not js. So why do you call it vbs? You used to call it .js which is javascript. vbs is visualbasic and will give errors if it contains javascript syntax
ASKER
-Does the script you ran beforehand look exactly like you posted it ? = Yes
-vbs is not js. So why do you call it vbs? = My mistake. Sorry for that.
I changed the extension of the script for "js" and here is the error message:
WebsiteMonitor.vbs(26,1) (null): Unspecified error
Thanks for your dedicated help,
Rene
-vbs is not js. So why do you call it vbs? = My mistake. Sorry for that.
I changed the extension of the script for "js" and here is the error message:
WebsiteMonitor.vbs(26,1) (null): Unspecified error
Thanks for your dedicated help,
Rene
But you still callit .vbs or the error would say
WebsiteMonitor.js(26,1) (null): Unspecified error
No?
Also the error is in the old code, which I now see could never work since you have quoted the variable that should hold the input file.
request.open( "GET", "objArgs(0)" , true );
should be
request.open( "GET", objArgs(0) , true );
WebsiteMonitor.js(26,1) (null): Unspecified error
No?
Also the error is in the old code, which I now see could never work since you have quoted the variable that should hold the input file.
request.open( "GET", "objArgs(0)" , true );
should be
request.open( "GET", objArgs(0) , true );
Try this and note the output
var objArgs = WScript.Arguments;
WScript.Echo("input: "+objArgs(0));
WScript.Echo("output: "+objArgs(1));
var request = new ActiveXObject("Msxml2.XMLHTTP");
var notyetready = true;
request.onreadystatechange=function() {
if(request.readyState==4) {
// WScript.Echo(request.responseText);
// Instantiate a File System ActiveX Object:
var fso = new ActiveXObject("Scripting.FileSystemObject");
// Invoke the method:
var a = fso.CreateTextFile(objArgs(1), true);
// Do something with it:
a.Write(request.responseText);
// Close the connection:
a.Close();
notyetready = false;
}
}
request.open( "GET", objArgs(0) , true );
request.send(null);
while( notyetready ) {
WScript.Sleep( 100 );
}
ASKER
I'm so sorry. I did not speep a lot the last 3 weeks so I tend to easely make typo mistake.
I re-wrote the error message by hand and made a finger glitch. It is indeed ".js".
I tried your sugggested code modification and got the same error message:
WebsiteMonitor.js(26,1) (null): Unspecified error
Here is my current test command line:
cscript //nologo "WebsiteMonitor.js" "www.google.com" "www.google.com.txt"
Thanks,
Rene
I re-wrote the error message by hand and made a finger glitch. It is indeed ".js".
I tried your sugggested code modification and got the same error message:
WebsiteMonitor.js(26,1) (null): Unspecified error
Here is my current test command line:
cscript //nologo "WebsiteMonitor.js" "www.google.com" "www.google.com.txt"
Thanks,
Rene
var request = new ActiveXObject("Msxml2.XMLHTTP");
var notyetready = 1;
request.onreadystatechange=function()
{
if(request.readyState==4)
{
WScript.Echo(request.responseText);
// Instantiate a File System ActiveX Object:
var fso = new ActiveXObject("Scripting.FileSystemObject");
// Invoke the method:
var a = fso.CreateTextFile(objArgs(1), true);
// Do something with it:
a.Write(request.responseText);
// Close the connection:
a.Close();
notyetready = 0;
}
}
var objArgs = WScript.Arguments;
WScript.Echo("objArgs(0)");
request.open( "GET", objArgs(0) , true );
request.send(null);
while( notyetready )
{
WScript.Sleep( 100 );
}
ASKER
My response was after your previous comment, not your last one. I will now test your script from your last comment.
Cheers,
Rene
Cheers,
Rene
ASKER
OUTPUT:
input: www.google.com
output: www.google.com.txt
WebsiteMonitor.js(23, 1) (null): Unspecified error
input: www.google.com
output: www.google.com.txt
WebsiteMonitor.js(23, 1) (null): Unspecified error
ASKER
With:
cscript //nologo "WebsiteMonitor.js" "http://www.google.com" "www.google.com.txt"
I do not get any errors, the output file is created but is empty
cscript //nologo "WebsiteMonitor.js" "http://www.google.com" "www.google.com.txt"
I do not get any errors, the output file is created but is empty
Here is one with more details (even more info at Microsoft)
var objArgs = WScript.Arguments;
WScript.Echo("input: "+objArgs(0));
WScript.Echo("output: "+objArgs(1));
var request = new ActiveXObject("Msxml2.XMLHTTP");
var notyetready = true;
request.onreadystatechange=function() {
if (request.status >= 400 && request.status <= 599){
WScript.Echo("Error Occurred : " + request.status + " - " + request.statusText);
return;
}
if(request.readyState==4) {
WScript.Echo(request.responseText);
// Instantiate a File System ActiveX Object:
var fso = new ActiveXObject("Scripting.FileSystemObject");
// Invoke the method:
var a = fso.CreateTextFile(objArgs(1), true);
// Do something with it:
a.Write(request.responseText);
// Close the connection:
a.Close();
notyetready = false;
}
}
request.open( "GET", objArgs(0) , true );
request.send(null);
while( notyetready ) {
WScript.Sleep( 100 );
}
ASKER
OUTPUT:
input: http://www.google.com
output: www.google.com.txt
WebsiteMonitor.js(9, 3) msxml3.dll: Unspecified error
WebsiteMonitor.js(9, 3) msxml3.dll: Unspecified error
input: http://www.google.com
output: www.google.com.txt
WebsiteMonitor.js(9, 3) msxml3.dll: Unspecified error
WebsiteMonitor.js(9, 3) msxml3.dll: Unspecified error
ASKER
Would you be more comfortable doing this in VBscript? If yes, well i'd actually prefer having this script in VBscript.
Thanks and cheers,
Rene
Thanks and cheers,
Rene
No way! I do JS, but rarely WSH
hard since I cannot test it myself until tomorrow.
Which I will - some 10 hours from now.
Now time for the family.
hard since I cannot test it myself until tomorrow.
Which I will - some 10 hours from now.
Now time for the family.
ASKER
I guess we'r in a same kind of boat.
What's you time zone? Me it's "-5GMT"
What's you time zone? Me it's "-5GMT"
GMT+1
ASKER
mplungjan,
Are you still on it?
Cheers,
Rene
Are you still on it?
Cheers,
Rene
Drat. I was, but gave up on your script and wanted to show it as an HTA
Do you have to do it from the command line or is it ok to have a small gui?
Do you have to do it from the command line or is it ok to have a small gui?
ASKER
I must not have a GUI.
I found a alternative solution.
I will close this thread and give you your points for your efforts and help.
Thanks and cheers,
Rene
I found a alternative solution.
I will close this thread and give you your points for your efforts and help.
Thanks and cheers,
Rene
ASKER
Even if this issue was not resolved here, your contribution have been greatly helpful and appreciated.
Thanks and cheers,
Rene
Thanks and cheers,
Rene
Hey, I am not done.
I'll look again tomorrow if you do not mind. But can I give you a gui instead of a commandline script?
I'll look again tomorrow if you do not mind. But can I give you a gui instead of a commandline script?
ASKER
This script is executed from a batch file and must not have a GUI. However, if you are up to the challange, that's fine with me.
Thanks again and cheers,
Rene
Thanks again and cheers,
Rene
Ok, I'll give it another go tomorrow
ASKER
Cool
Sorry. I did not get any results from my inquiries.
I suggest you ask the question again in the scripting zone
I suggest you ask the question again in the scripting zone
ASKER
Dont worry
Thanks a lot for everything.
Cheers,
Rene
Thanks a lot for everything.
Cheers,
Rene
var request = new ActiveXObject("Msxml2.XMLH
var notyetready = 1;
request.onreadystatechange
{
if(request.readyState==4)
{
WScript.Echo(request.respo
// Instantiate a File System ActiveX Object:
var fso = new ActiveXObject("Scripting.F
// Invoke the method:
var a = fso.CreateTextFile(objArgs
// Do something with it:
a.Write(request.responseTe
// Close the connection:
a.Close();
notyetready = 0;
}
}
var objArgs = WScript.Arguments;
WScript.Echo("objArgs(0)")
request.open( "GET", "objArgs(0)" , true );
request.send(null);
while( notyetready )
{
WScript.Sleep( 100 );
}