Suk*_*tto 5 windows vbscript scripting batch-file jscript
我需要为WinXP编写一些脚本来支持Big Financial Corp.的一些分析师.请帮我确定哪种类型的Windows脚本最适合我的需求.
我的需求看起来很简单(无论如何对我来说)
从我对我的选择的匆忙审查,看起来我的选择
我没有时间学习或深入研究这些(或者其他任何可用的标准WinXP安装).我迫切需要尽快选择和破解一些东西.
(目前的危机是需要运行给定的应用程序,传递几个日期参数).
一旦目前的危机结束,就会有更多这样的要求.
帮助我Obi Wan Stackoverflow ...你是我唯一的希望.
[edit]我目前的技能包括Perl,Javascript和Java,所以我最喜欢使用类似的东西
[编辑]好的.我将尝试在JScript中编写WSH文件.谢谢大家......一旦事情在这里安定下来,我会让你知道它是怎么回事(并想出一个接受答案).
[编辑]最终都解决了.感谢快速响应的人们.这是我给用户的内容
<job id="main">
<script language="JScript">
// ----- Do not change anything above this line ----- //
var template = "c:\\path\\to\\program -##PARAM## --start ##date1## --end ##date2## --output F:\\path\\to\\whereever\\ouput_file_##date1##.mdb";
// Handle dates
// first, figure out what they should be
dt = new Date();
var date1 = stringFromDate(dt, 1);
var date2 = stringFromDate(dt, 2);
// then insert them into the template
template = template.replace(new RegExp("##date1##", "g"), date1);
template = template.replace(new RegExp("##date2##", "g"), date2);
// This application needs to run twice, the only difference is a single parameter
var params = ["r", "i"]; // here are the params.
// set up a shell object to run the command for us
var shellObj = new ActiveXObject("WScript.Shell");
// now run the program once for each of the above parameters
for ( var index in params )
{
var runString = template; // set up the string we'll pass to the wondows console
runString = runString.replace(new RegExp("##PARAM##", "g"), params[index]); // replace the parameter
WScript.Echo(runString);
var execObj = shellObj.Exec( runString );
while( execObj.Status == 0 )
{
WScript.Sleep(1000); //time in milliseconds
}
WScript.Echo("Finished with status: " + execObj.Status + "\n");
}
// ----- supporting functions ----- //
// Given a date, return a string of that date in the format yyyy-m-d
// If given an offset, it first adjusts the date by that number of days
function stringFromDate(dateObj, offsetDays){
if (typeof(offsetDays) == "undefined"){
offsetDays = 0;
}
dateObj.setDate( dateObj.getDate() + offsetDays );
var s = dateObj.getYear() + "-"; //Year
s += (dateObj.getMonth() + 1) + "-"; //Month (zero-based)
s += dateObj.getDate(); //Day
return(s);
}
// ----- Do not change anything below this line ----- //
</script>
</job>
Run Code Online (Sandbox Code Playgroud)
显然它可能会更好......但它完成了工作,并且很容易让我的用户理解和扩展自己.
sni*_*ker 27
从技术上讲,这些在语法上都是一样的.实际上WScript/CScript是引擎,VBScript和JScript是语言.
个人意见仅限于:我的个人推荐是JScript,因为它让我想起了更多真正的编程语言,并且让我想要比VBScript 更少地打击自己.鉴于您对javascript的熟悉,最好的选择是JScript.
更详细地了解WScript和CScript之间的区别,就像其他人一样:这些是Windows脚本宿主脚本的执行平台.它们本质上是相同的,而WScript更面向GUI,而CScript更倾向于面向控制台.如果使用CScript启动脚本,您将看到一个控制台窗口,但您仍然可以访问GUI功能,而如果您从WScript开始,则没有控制台窗口,并且许多默认输出方法显示为窗口对象而不是控制台中的一行.
| 归档时间: |
|
| 查看次数: |
10142 次 |
| 最近记录: |