Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

JS file running from CMD and document.write

external JS files triggered by Batch process



5:13 pm on Mar 30, 2012 (gmt 0)

5+ Year Member

here is my script:

var LOCALPATH = ".\\";

var REMOTEPATH = "/";

var FILE = "winscp421.exe";

var SESSION = "test@";

var WINSCP = "c:\\program files\\winscp

function pad(n, len)
var s = n.toString();
while (s.length < len)
s = '0' + s;
return s;

var date = new Date();

// format timestamp
var stamp =pad(date.getFullYear(), 4) + pad(date.getMonth(), 2) + pad(date.getDate(), 2);

document.write("Date Job:" +stamp);

This script should be triggered by batch process(bat file from Microsoft scheduler).
At this point all what I need is to confirm that date get written into variable stamp.
Result is error:


C:\>cscript c:\test.js
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

c:\test.js(28, 1) Microsoft JScript runtime error: 'document' is undefined

Why and how I can fix this. Normally all my JS files works fine but here I hit brick wall....


5:54 pm on Mar 30, 2012 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

There is no "document" object in the context of Windows Script Host. Replace document.write with WScript.Echo, and I think that will give you what you want.


3:03 pm on May 10, 2012 (gmt 0)

5+ Year Member

I solved it.
It was a permission issue for the user running batch job in scheduler on all folders involved into this job.

Featured Threads

Hot Threads This Week

Hot Threads This Month