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)

New User

5+ Year Member

joined:Apr 15, 2009
posts: 3
votes: 0

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)

Senior Member from US 

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

joined:Oct 17, 2005
posts: 5007
votes: 21

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)

New User

5+ Year Member

joined:Apr 15, 2009
votes: 0

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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members