TomMonkey
asked on
Getting Variable from JScript in Batch File
Hi Guys,
I am trying to write some batch files and have got a bit stuck. The batch program calles a JScript prgram to get the name of a folder created three days ago:
// Create Date object
objToday = new Date();
// Get today's year, month and day
year = objToday.getFullYear();
month = objToday.getMonth() + 1;
if ( month < 10 )
{
month = "0" + month;
};
day = objToday.getDate();
if ( day < 10 )
{
day = "0" + day;
};
// Format output for today
strToday = "Today: " + year + month + day + " (" + day;
strToday = strToday + "/" + month + "/" + year + ")";
// Get current date in milliseconds since January 1, 1970
today = objToday.valueOf();
// Subtract 3 days
threeDay = 1000 * 24 * 60 * 60 * 3;
yesterday = today - threeDay;
objToday.setTime(yesterday );
// Get threeDay's year, month and day
year = objToday.getFullYear();
month = objToday.getMonth() + 1;
if ( month < 10 )
{
month = "0" + month;
};
day = objToday.getDate();
if ( day < 10 )
{
day = "0" + day;
};
// Format output
strFolder = "" + year + month + day;
//display output
//WScript.echo( strFolder );
WScript.quit( strFolder );
The problem is I can't get the variable strFolder to be returned to the batch script. I have tried:
OldFolder.js %*
echo %strFolder%
and
for /f "tokens=*" %%i in ('OldFolder.js') do set var=%%i
echo %var%
But neither have worked. What am I doing wrong please?
Cheers
Tom
I am trying to write some batch files and have got a bit stuck. The batch program calles a JScript prgram to get the name of a folder created three days ago:
// Create Date object
objToday = new Date();
// Get today's year, month and day
year = objToday.getFullYear();
month = objToday.getMonth() + 1;
if ( month < 10 )
{
month = "0" + month;
};
day = objToday.getDate();
if ( day < 10 )
{
day = "0" + day;
};
// Format output for today
strToday = "Today: " + year + month + day + " (" + day;
strToday = strToday + "/" + month + "/" + year + ")";
// Get current date in milliseconds since January 1, 1970
today = objToday.valueOf();
// Subtract 3 days
threeDay = 1000 * 24 * 60 * 60 * 3;
yesterday = today - threeDay;
objToday.setTime(yesterday
// Get threeDay's year, month and day
year = objToday.getFullYear();
month = objToday.getMonth() + 1;
if ( month < 10 )
{
month = "0" + month;
};
day = objToday.getDate();
if ( day < 10 )
{
day = "0" + day;
};
// Format output
strFolder = "" + year + month + day;
//display output
//WScript.echo( strFolder );
WScript.quit( strFolder );
The problem is I can't get the variable strFolder to be returned to the batch script. I have tried:
OldFolder.js %*
echo %strFolder%
and
for /f "tokens=*" %%i in ('OldFolder.js') do set var=%%i
echo %var%
But neither have worked. What am I doing wrong please?
Cheers
Tom
ASKER
Hi MSE-dwells,
I have tried running it at the command prompt and the output always appears in a dialog box. How do I get it to appear just in the console?
I have tried running it at the command prompt and the output always appears in a dialog box. How do I get it to appear just in the console?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sheesh, nobody likes you Steve ;0) ... teasing of course.
Do exactly as SteveGTR describes ... it reduced my typing anyway ... hehehe!
Do exactly as SteveGTR describes ... it reduced my typing anyway ... hehehe!
TomMonkey tapped into what little knowledge I know about these scripts ;)
ASKER
Brilliant, works like a charm.
Thanks to both of you for quick responses.
Tom
Thanks to both of you for quick responses.
Tom
If you run oldfolder.js at the command prompt, what do you receive?