5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CMDファイルで JScript

Last updated at Posted at 2015-06-26
RunInBAT.CMD
@if(0)==(0) REM /* Shift-JIS(シフトJIS)で書かないとエラーになる・・・当然か
ECHO OFF
PUSHD %~dp0
CScript.exe //NoLogo //E:JScript "%~f0" %*
POPD
GOTO :EOF
REM */
@end

WScript.Echo('コマンドラインで実行中');
wshShell = new ActiveXObject('WScript.Shell');
wshShell.Popup('完了!',5);

RunWithCscript.js
@if(0)==(0) REM /* Shift-JIS(シフトJIS)で書かないとエラーになる・・・当然か
ECHO OFF
PUSHD %~dp0
CScript.exe //NoLogo //E:JScript "%~f0" %*
POPD
GOTO :EOF
REM */
@end
/*
* JavaScriptのいろいろなコーディングルールをまとめてみた
** http://efcl.info/2011/0527/res2764/
* 他人にやさしいソースコードの書き方 コーディング規約 JavaScript編
** http://www.hp-stylelink.com/news/2013/10/20131008.php
*/

//	コマンドラインで実行!
RunInCscript();

WScript.Echo('コマンドラインで実行中');
wshShell = new ActiveXObject('WScript.Shell');
wshShell.Popup('完了!',5);

/**
 * WSCRIPT で実行中だったら、CSCRIPT で再実行する。
 */
function RunInCscript() {
	var path = WScript.FullName.toUpperCase();
	if (path.search('CSCRIPT\.EXE$') >= 0) {
		return;
	}
	var cmd = 'CSCRIPT.EXE //NoLogo //E:JScript ' + WScript.ScriptFullName;
	var args = WScript.Arguments
	var n = args.length;
	var i;
	for (i=0;i<n;i++) {
		var arg = args(i);
		if (arg.search('\ ') >= 0) {
			arg = '"' + arg + '"';
		}
		cmd += ' ' + arg;
	}
	wshShell = new ActiveXObject('WScript.Shell');
	var r = wshShell.Run(cmd,5,true);
//	wshShell.Popup('done!',5);
	WScript.Quit(r);
}

function echo(msg) {
	WScript.Echo(msg);
}

参考サイト

http://180.cocolog-nifty.com/blog/2011/12/jscript-aca0.html
http://blogs.msdn.com/b/joshpoley/archive/2008/01/15/running-jscript-in-a-cmd-file.aspx

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?