Error argument in BAT-file from Button

Please report only one bug per message!

Moderators: Stefan2, white, sheep, Hacker

Post Reply
Ciber SLasH
Junior Member
Junior Member
Posts: 7
Joined: 2013-04-25, 14:42 UTC

Error argument in BAT-file from Button

Post by *Ciber SLasH » 2016-06-13, 12:52 UTC

Hi all!
Button:

Code: Select all

TOTALCMD#BAR#DATA
cmd.exe /K
"%%Commander_Path%%\Scripts\ReadCL.bat" "D:\Soft\#CMD tools\MTEE\mtee.bat"
%Commander_Path%\WCMICONS.DLL,74
ReadCL


-1
ReadCL.bat:

Code: Select all

@echo off
echo [ %~nx0 :: Arguments ]
echo 1-9: %1 %2 %3 %4 %5 %6 %7 %8 %9
echo --------------------------------------------------------------------------------
echo %% 1: %1
echo %% 2: %2
echo %% 3: %3
echo %% 4: %4
echo %% 5: %5
echo %% 6: %6
echo %% 7: %7
echo %% 8: %8
echo %% 9: %9
pause
Press button & have error.
also have error:

Code: Select all

TOTALCMD#BAR#DATA
cmd.exe /K
"%%Commander_Path%%\Scripts\ReadCL.bat" "1"
%Commander_Path%\WCMICONS.DLL,74
ReadCL


-1

User avatar
Dalai
Power Member
Power Member
Posts: 6153
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai » 2016-06-13, 13:10 UTC

That's not TC's fault, it's the CMD syntax you have to follow here. Just quote to whole parameters field to make it work:

Code: Select all

TOTALCMD#BAR#DATA
cmd.exe /K
""%%Commander_Path%%\Scripts\ReadCL.bat" "D:\Soft\#CMD tools\MTEE\mtee.bat""
%Commander_Path%\WCMICONS.DLL,74
ReadCL


-1
Yes, it may look weird, but that's how it works.

Regards
Dalai
#101164 Personal licence
Athlon X4 880K, 16 GiB RAM, Gigabyte F2A88X-D3HP, Win7 x64

Plugins: Services2, Startups

Ciber SLasH
Junior Member
Junior Member
Posts: 7
Joined: 2013-04-25, 14:42 UTC

Post by *Ciber SLasH » 2016-06-13, 15:20 UTC

Double quote hack not good idea.
Arguments maybe from %P%N.
I make JScript
Run.js

Code: Select all

/*
[ For execute EXE|CMD|BAT ]
@name	Run.js
@ver	1.00
@author	Ciber SLasH
@cDate	2013-11-22
@mDate	2016-06-13
*/
//------------------------------------------------------------------------------
var DEBUG = 0;
var MAXIMIZE = 0;
//------------------------------------------------------------------------------
SW_SHOWMAXIMIZED = 2;
WshShell = WScript.CreateObject('WScript.Shell');
//------------------------------------------------------------------------------
if (WScript.Arguments.length == 0) {
	showMsgEx('Empty arguments!', 'warning');
	Quit(-1);
}
//------------------------------------------------------------------------------
var cmdLine = "";
for (var i = 0; i < WScript.Arguments.length; i++) {
	var param = WScript.Arguments.Item(i);
	if (param.toUpperCase() == '/MAX') {
		MAXIMIZE = 1;
	} else if (param.toUpperCase() == '/DEBUG') {
		DEBUG = 1;
	} else {
		if (/%\w+%/.test(param))	param = WshShell.ExpandEnvironmentStrings(param);
		if (param.substr(0,1) != '"' && param.indexOf("\\") != -1)	param = '"'+param+'"';
		cmdLine += param + ' ';
	}
}
cmdLine = cmdLine.slice(0, -1);
//------------------------------------------------------------------------------
if (DEBUG == 1)
	showMsgEx('cmdLine:\n\n' + cmdLine);
else {
	if (MAXIMIZE == 0)
		WshShell.Run(cmdLine);
	else
		WshShell.Run(cmdLine, SW_SHOWMAXIMIZED);
}
//------------------------------------------------------------------------------
Quit(0);
////////////////////////////////////////////////////////////////////////////////
//==[ Funcs ]===================================================================
////////////////////////////////////////////////////////////////////////////////
//--[ Quit from script ]--------------------------------------------------------
function Quit(exitCode) {
	FreeObjects();
	WScript.Quit(exitCode);
}
//--[ Free objects from memory ]------------------------------------------------
function FreeObjects() {
	if (typeof(FSO) != 'undefined')			FSO.Quit;
	if (typeof(WshShell) != 'undefined')	WshShell.Quit;
}
/*
[ Show extended message ]
@param1 msg (String)		- message
*@param2 msgType (String)	- message type: error|warning (default: "info")
*@param3 caption (String)	- message caption
--------------------------------------------------------------------------------
Used "WshShell.Popup"
*/
function showMsgEx(msg, msgType, caption) {
// Consts button
var MB_OK = 0x0;
// Consts icons
var MB_ICONERROR = 0x10;
var MB_ICONWARNING = 0x30;
var MB_ICONINFORMATION = 0x40;
	msgType = msgType ? msgType.toUpperCase() : '';
	caption = caption ? ': '+caption : '';
	caption = WScript.ScriptName+' ]' + caption;
	switch (msgType) {
		case 'ERROR':
			msgType = MB_ICONERROR;
			caption = '[ ERROR :: '+caption;
			break;
		case 'WARNING':
			msgType = MB_ICONWARNING;
			caption = '[ Warning :: '+caption;
			break;
		default:
			msgType = MB_ICONINFORMATION;
			caption = '[ Info :: '+caption;
			break;
	}
	WshShell.Popup(msg, 0, caption, MB_OK | msgType);
}
and make button:

Code: Select all

TOTALCMD#BAR#DATA
Run.js
?"%%Commander_Path%%\..\#CMD tools\MTEE\mtee.bat" %P%N
%Commander_EXE%,2
bat::run -> MTEE
%Commander_Path%\Scripts\

-1

User avatar
Dalai
Power Member
Power Member
Posts: 6153
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai » 2016-06-13, 15:49 UTC

Ciber SLasH wrote:Double quote hack not good idea.
That's no hack at all. It's just the way CMD expects its arguments. Look it up by typing CMD /? in a CMD window.
Arguments maybe from %P%N.
So? It works the same way, regardless of TC quoting %P%N or not. If you need to remove the quotes in the batch, just use %~1 through %~9; the same applies to for-loop variables, i.e. %%i doesn't remove quotes around the contents of i while %%~i removes them.

Regards
Dalai
#101164 Personal licence
Athlon X4 880K, 16 GiB RAM, Gigabyte F2A88X-D3HP, Win7 x64

Plugins: Services2, Startups

Ciber SLasH
Junior Member
Junior Member
Posts: 7
Joined: 2013-04-25, 14:42 UTC

Post by *Ciber SLasH » 2016-06-13, 15:58 UTC

Button1:

Code: Select all

TOTALCMD#BAR#DATA
cmd.exe /K
"%%Commander_Path%%\Scripts\ReadCL.bat" %P%N
%Commander_EXE%,3
Test command
%Commander_Path%\Scripts\

-1
Button2:

Code: Select all

TOTALCMD#BAR#DATA
cmd.exe /K
"%%Commander_Path%%\Scripts\ReadCL.bat" "%P%N"
%Commander_EXE%,3
Test command
%Commander_Path%\Scripts\

-1
both - error.
Press ButtonX on path "D:\Soft\#CMD tools\MTEE\mtee.bat"
ReadCL.bat - empty.

User avatar
Dalai
Power Member
Power Member
Posts: 6153
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai » 2016-06-13, 16:06 UTC

I already said that you need to quote the whole parameter field. If you do, %P%N works as well as any other parameter.

Note that you must not quote %P%N, TC does that by itself if they contain spaces.

Regards
Dalai
#101164 Personal licence
Athlon X4 880K, 16 GiB RAM, Gigabyte F2A88X-D3HP, Win7 x64

Plugins: Services2, Startups

Post Reply